Hide/Show list options?
tchnclrwhscsh
17 Feb 2023, 15:21Hi everyone, so, I am brand new to this and I'm not super familiar with coding. I'm trying to make it so that there's an option in a list you have to unlock by first using another option from that list, and then once you use that option it adds the hidden option to the list. I'm sure it's something relatively simple but as stated I am very new to this and cannot for the life of me figure out what I should select/code to have this occur, so any help would be appreciated.
mrangel
17 Feb 2023, 16:07To add items to a list, you can just use list add
.
For example, if you have a stringlist held in the variable options
, you would add an option to it using the script:
list add (options, "New item")
If you're using the list for a menu, you'd probably want to put it in an attribute so that you can access the same variable later.
For example, a "talk to" verb might have a script something like:
// Create the list the first time the code runs
firsttime {
bob.questions = Split("What's your name?;What's your job?;What's your favourite colour?")
}
ShowMenu ("What do you want to ask Bob?", bob.questions, true) {
switch (result) {
case ("What's your name?") {
msg ("Bob!")
}
case ("What's your job?") {
msg ("I used to be a plumber, but I quit.")
list add (bob.questions, "Why did you quit?")
}
case ("What's your favourite colour?") {
msg ("Green!")
}
case ("Why did you quit?") {
// This option might unlock some other ones
msg ("Because my boss was a lizard person.")
}
default {
error ("If you see this, one of the options is spelled wrong. The option you chose was: '" + result + "'")
}
}
}