Menu Structure
GAGE HOLSTON
26 Apr 2020, 02:57In my game, the player at one point gains access to a computer terminal in a store and has to use it to buy something. What I would like to do is have a menu the player has to go through to get to the item, but there are other stuff the player can look at it and essitentally have this whole system of menus to go through
For Example
Player uses the terminal and gets the following choices in a menu
1- Item Set A
2- Item Set B
3- Item Set C
4- Leave (Exit Terminal)
The player chooses Item Set A
1- Item 1
2- Item 2
3- Item 3
4- Return (Takes them back to Item Set Menu)
The player chooses Item 1
(Description of Item 1)
1- Buy (Will trigger an event if the player is allowed. Otherwise throws up a message saying why the player can't buy it)
2- Return (Back to Item menu)
That might be a little too complicated, but I felt it would just be something fun the player can mess around with while also getting the item they actually need, like the RadioShock/Hz. So Good from SQ4.
The main issue, as the topic name might indicate, is how would I go pulling this off in Quest? And will I actually be able to follow how to do it?
mrangel
26 Apr 2020, 11:59You could make a function for each menu, with an option which calls the function for the menu above. But I'd probably end up doing something like:
<function name="shopmenu" parameters="submenu">
if (not HasAttribute (game, "menuoptions")) {
game.menuoptions = NewDictionary()
dictionary add (game.menuoptions, "A", Split("item1;item2;item3"))
dictionary add (game.menuoptions, "B", Split("item3;item4;item5"))
dictionary add (game.menuoptions, "C", Split("item6;item7"))
dictionary add (game.menuoptions, "buy:item5", "Sorry, that item is out of stock")
mainmenu = NewStringDictionary()
dictionary add (mainmenu, "A", "Item Set A")
dictionary add (mainmenu, "B", "Item Set B")
dictionary add (mainmenu, "C", "Item Set C")
dictionary add (mainmenu, "examples", "Silly examples of things this script can do")
dictionary add (mainmenu, "exit_menu", "Leave")
dictionary add (game.menuoptions, "main", mainmenu)
// Some silly examples
dictionary add (game.menuoptions, "examples", Split("alarm;explode"))
alarmscript => {
msg ("The alarm starts going off! Security might be here soon")
game.alarm_sounded = true
shopmenu ("return")
}
dictionary add (game.menuoptions, "alarm", alarmscript)
explodescript => {
msg ("The terminal explodes!")
RemoveObject (shop terminal)
shopmenu ("exit_menu")
}
dictionary add (game.menuoptions, "alarm", alarmscript)
game.parentmenu = NewStringList()
}
switch (submenu) {
case ("exit_menu") {
ShowRoomDescription()
game.menuoptions = null
game.parentmenu = null
}
case ("return", "Return to previous menu") {
currentmenu = ListItem (game.parentmenu, 0)
list remove (game.parentmenu, currentmenu)
previousmenu = ListItem (game.parentmenu, 0)
list remove (game.parentmenu, previousmenu)
shopmenu (previousmenu)
}
default {
// clunky way to add an item to the beginning of a list:
game.parentmenu = ListCombine (Split(submenu), game.parentmenu)
if (DictionaryContains (game.menuoptions, submenu)) {
options = DictionaryItem (game.menuoptions, submenu)
if (TypeOf (options) = "string") {
// It's a "sorry you can't buy that" message
msg (options)
wait {
shopmenu ("return")
}
}
else if (TypeOf (options) = "script") {
invoke (options)
}
else {
if (EndsWith(TypeOf(options), "dictionary")) {
if (not DictionaryContains (options, "return") and not DictionaryContains (options, "exit_menu") ) {
if (not DictionaryContains (options, "return")) {
dictionary add (options, "return", "Return to previous menu")
}
}
}
else {
if (not ListContains (options, "return") and not ListContains (options, "exit_menu") ) {
list add (options, "Return to previous menu")
}
}
ShowMenu ("Choose an option!", options, false) {
shopmenu (result)
}
}
}
else if (not GetObject (submenu) = null) {
item = GetObject (submenu)
// Add whatever code you want to use for displaying the object; I just use its name and 'look' description
msg ("{b:{object:"+submenu+"}}")
msg (GetString (item, "look"))
options = NewStringDictionary()
dictionary add (options, "buy:"+submenu, "Buy")
dictionary add (options, "return"+submenu, "Return")
ShowMenu ("Buy this item?", options, false) {
shopmenu (result)
}
}
else if (StartsWith (submenu, "buy:")) {
item = GetObject (Mid (submenu, 5))
AddToInventory (item)
msg ("You purchase the {object:"+item+"}")
// We probably want to return to the list of items, not to the item we just bought, so these 2 lines go up an extra level
currentmenu = ListItem (game.parentmenu, 0)
list remove (game.parentmenu, currentmenu)
shopmenu ("return")
}
else {
error ("Can't find menu:" + submenu)
}
}
}
</function>
GAGE HOLSTON
28 Apr 2020, 01:12OK, I got it working. Thanks for the help.