I need to know how to take options out of a list.

Thickar
11 Nov 2022, 02:09

Hello there. I haven't used quest in years. Unfortunately, my hard drive that had a game I was working on previously got lost when the hard drive crashed. Thankfully I kept the code for the most important part of the game, hover I lost all the code for the small things I did.
In this case, the last time someone helped me figure out how to take a command like talk and create a list of responses, when selected it randomly uses one, and only when it used it's removed from the list. That way, when all used, the game moves forward.'
Can anyone remind me how to do that?


mrangel
11 Nov 2022, 08:47

I assume you're using a list attribute to to store the list of responses? In that case you can just use list remove.

This would make the NPC's "talk to" verb look something like:

if (ListCount (bob.options) = 0) {
  msg (You don't have anything to say to him.")
}
else {
  ShowMenu ("What do you want to say to Bob?", bob.options, true) {
    list remove (bob.options, result)
    switch (result) {
      case ("Hi") {
        msg ("Bob says hi back")
      }
      case ("What's your name?") {
        msg ("“Uhh… Bob. Like it says on my name badge.”")
      }
      case ("What's the capital of Albania?", "What is the airspeed velocity of an unladen swallow?") {
        msg ("Bob says “I don't know!”")
      }
    }
  }
}

That's assuming that all the things you can say are stored in bob.options. If you're using the web editor, you'd need to put something like this in a firsttime script, or if (not HasAttribute (bob, "options")) {:

bob.options = Split ("Hi;What's your name?;What's the capital of Albania?;What is the airspeed velocity of an unladen swallow?")