How to ask questions with menus?

So currently I'm working on a game project in which a big thing is that the player has to answer a bunch of multiple choice trivia questions(specifically, with the answers being A B C or D, with the occasional E), I was wondering how exactly I would go about making that work. I haven't been able to make much sense of the page for the show menu script.

What I'm looking for is basically just some help figuring out how to add multiple response option to the menu, and how to make different responses have a different outcome, that second one I'm pretty sure comes down to having an IF statement for when result = (something), but I don't know what the somethings would be.


J_J

Here is the code. You can add as many questions as you want. Option 1 gives an example of having multiple trivia questions. You just paste the same code inside each option, the way it looks in Option 1. I'd suggest pasting this into your games code, and then going back to the editor. I think when you're new to menus it's really easy to mess up the code. The editor is easy to use.


J_J

Quest won't let me edit my last post. So ignore that.

Here is the code. You can add as many questions as you want. Option 1 gives an example of having multiple trivia questions. You just paste the same code inside each option, the way it looks in Option 1. I'd suggest pasting this into your games code, and then going back to the editor. I think when you're new to menus it's really easy to mess up the code. The editor is easy to use.

options = Split("Option 1;Option 2;Option 3", ";")
ShowMenu ("\"Question Here?\"", options, false) {
  switch (result) {
    case ("Option 1") {
      msg ("What happens when you answer. <br/><br/>Here is where you could also put in the same code again with another question if there are multiple trivia questions. Just go to code mode, and paste in the same code again but change the question. Easy.<br/>")
      options = Split("Option 1;Option 2;Option 3", ";")
      ShowMenu ("\"Question Here?\"", options, false) {
        switch (result) {
          case ("Option 1") {
            msg ("What happens when you answer. <br/><br/>Here is where you could also put in the same code again with another question if there are multiple trivia quesitons. Just go to code mode, and paste in the same code again but change the question. Easy.<br/>")
          }
          case ("Option 2") {
            msg ("What happens when you answer. <br/><br/>Here is where you could also put in the same code again with another question if there are multiple trivia quesitons. Just go to code mode, and paste in the same code again but change the question. Easy.<br/>")
          }
          case ("Option 3") {
            msg ("What happens when you answer. <br/><br/>Here is where you could also put in the same code again with another question if there are multiple trivia quesitons. Just go to code mode, and paste in the same code again but change the question. Easy.")
          }
        }
      }
    }
    case ("Option 2") {
      msg ("What happens when you answer. <br/><br/>Here is where you could also put in the same code again with another question if there are multiple trivia quesitons. Just go to code mode, and paste in the same code again but change the question. Easy.<br/>")
    }
    case ("Option 3") {
      msg ("What happens when you answer. <br/><br/>Here is where you could also put in the same code again with another question if there are multiple trivia quesitons. Just go to code mode, and paste in the same code again but change the question. Easy.")
    }
  }
}

Hmm, strange, I can't seem to get it to work. If I change the name of the options(either what they show up as or what they are listed as in the case list) then it says Error running script: Error compiling expression '(whatever I set the first option to in the case list)': Unknown object or variable '(same as before)'. It works fine if I do it exactly as you posted it, but it seems like I can't seem to change anything at all about it without breaking it in some way.

I tried having objects with the same name as the answers as well, but then it just didn't run the script associated with the option.


in the 'cases', make sure you got it encased within the double quotes:

case ("WHATEVER") { SCRIPTING }

this gets into Data Types:

Strings ("text") vs Objects (reference/pointer)

anything within double quotes is a String

so, since you're using a String List (the 'split'Script/Function can only create a String List), you're using Strings as your item's Values:

item1:
Key (String): "WHATEVER"
Value (String): "WHATEVER"

and thus, your 'cases' must be checking String Values


example of what's going on with it:

string_variable = "dragon"

switch (string_variable) { case ("dragon") { SCRIPTING} === if (string_variable = "dragon") { SCRIPTING }

is 'string_variable' the same as "dragon" ???

// if (string_variable = "dragon")
// if ([string_variable = "dragon"] = "dragon")
// if (["dragon"] = "dragon")
//
// if (["d"] = "d") ---> true
// if (["r"] = "r") ---> true
// if (["a"] = "a") ---> true
// if (["g"] = "g") ---> true
// if (["o"] = "o") ---> true
// if (["n"] = "n") ---> true
// if (["dragon"] = "dragon") ---> TRUE

~~~~ VS ~~~~

string_variable = "dragon"

switch (string_variable) { case ("dragoN") { SCRIPTING} === if (string_variable = "dragoN") { SCRIPTING }

is 'string_variable' the same as "dragoN" ???

// if (string_variable = "dragoN")
// if ([string_variable = "dragon"] = "dragoN")
// if (["dragon"] = "dragoN")
//
// if (["d"] = "d") ---> true
// if (["r"] = "r") ---> true
// if (["a"] = "a") ---> true
// if (["g"] = "g") ---> true
// if (["o"] = "o") ---> true
// if (["n"] = "N") ---> false
// if (["dragon"] = "dragoN") ---> FALSE

~~~~ VS ~~~~

string_variable = "dragoN"

switch (string_variable) { case ("dragon") { SCRIPTING} === if (string_variable = "dragon") { SCRIPTING }

is 'string_variable' the same as "dragon" ???

// if (string_variable = "dragon")
// if ([string_variable = "dragoN"] = "dragon")
// if (["dragoN"] = "dragon")
//
// if (["d"] = "d") ---> true
// if (["r"] = "r") ---> true
// if (["a"] = "a") ---> true
// if (["g"] = "g") ---> true
// if (["o"] = "o") ---> true
// if (["N"] = "n") ---> false
// if (["dragoN"] = "dragon") ---> FALSE


(filler for getting my edited post, updated/posted)


String Lists vs Object Lists


String Lists:

string_list_variable = Split ("red;blue;yellow", ";")

// or (alternative):

string_list_variable = NewStringList ()
list add (string_list_variable, "red")
list add (string_list_variable, "blue")
list add (string_list_variable, "yellow")

the 'string_list_variable' String List Variable:

(the index number is automatic, starting at '0', NOT '1', and counts up for each item added)

item 1:
input: index number (key): 0
output: value: "red"

item 2:
input: index number (key): 1
output: value: "blue"

item 3:
input: index number (key): 2
output: value: "yellow"

string_variable = StringListItem (string_list_variable, GetRandomInt (0,2))
msg (string_variable)
// output: [RANDOM SELECTION: "red" or "blue" or "yellow"]


Object Lists:

// creating the 'red', 'blue', and 'yellow' Objects:
create ("red")
create ("blue")
create ("yellow")

object_list_variable = NewObjectList ()
list add (object_list_variable, red)
list add (object_list_variable, blue)
list add (object_list_variable, yellow)

the 'object_list_variable' Object List Variable:

(the index number is automatic, starting at '0', NOT '1', and counts up for each item added)

item 1:
input: index number (key): 0
output: value: red // (as a hyperlink of the 'red' Object)

item 2:
input: index number (key): 1
output: value: blue // (as a hyperlink of the 'blue' Object)

item 3:
input: index number (key): 2
output: value: yellow // (as a hyperlink of the 'yellow' Object)

object_variable = ObjectListItem (object_list_variable, GetRandomInt (0,2))
msg (object_variable)
// output: [RANDOM SELECTION: 'red' or 'blue' or 'yellow'] // (as a hyperlink of the randomly selected Object)


Works like a charm, thanks!


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums