Returning Show Menu option's number, rather than string? [Solved]

Io

Is there a way to, when a player selects an option from Show Menu, to get the number of the choice rather than the choice itself? So for example, the player sees:

Make a Choice!
1. OPEN THE DOOR
2. OPEN THE DOOR
3. OPEN THE DOOR

And they select option 2. Is there a way to get different things to happen if you choose a different option? Ie OPEN THE DOOR 1 does a different thing than OPEN THE DOOR 2, even though they both give the same string 'result' variable?


Short answer... Yes.
But "result" should have different values.


Io

And long answer?


What happens if you use a stringdictionary instead of a stringlist for the menu of items? The key that the player selects (which is different) will go into result, but maybe the key's value (which would be same) could be dislayed in the menu instead? Just a thought.


Another thing I thought of is -- what if you use an object list instead of a string list? I don't remember if an object list in a menu shows a list of object names or aliases, but if the latter, you could list different objects with the same aliases.


Dcoder is onto something . . .

In this example, I'm just making it print 1, 2, or 3, depending on which "Open the door." the player chooses.

options = NewStringDictionary()
dictionary add (options, "1", "Open the door.")
dictionary add (options, "2", "Open the door.")
dictionary add (options, "3", "Open the door.")
ShowMenu ("Make a choice!", options, false) {
  msg (result)
}

http://docs.textadventures.co.uk/quest/using_dictionaries.html#some-uses-of-dictionaries


Io

Thanks, using a dictionary works perfectly!


"That was the long answer"...


I've created (well, still creating) my own menu system (currently for my character creation, but hope it'll eventually work for entire game too), as I like being able to just type in a number for a choice, here's an example of it:

http://textadventures.co.uk/forum/quest/topic/7un74f7l1ei6owtf2oukmw/including-walkthrough-question-delete-this-post-please#e2d1bff7-7978-4d27-9c41-3d4ac3cdf115

if you're interested, and if you need help with anything or don't understand something, let me know!


Log in to post a reply.

Support

Forums