Login
Remember
IF Answers
Ask a Question

# How do I ask questions in Quest?

0 votes
390 views
asked May 13 in Authoring by Steven
recategorized May 13 by Alex

I would like to ask the player a question. After that , the player will type a answer. If the answer is correct, the game will print a message.

For instance, when the player is playing, they enter into a room and have a question.
The question is" one plus one equal?"

After that, the player types "two", the game print message "you answer correct".

- quest

## 2 Answers

+1 vote
answered May 15 by The Pixie (121 points)

Here is a script that will do just that:

    msg("What does one plus one equal?")
    get input {
      if (IsRegexMatch(result, "(2|two)")) {
        msg("You answered correctly!")
      }
      else {
        msg("Not even close.")
      }
    }

The get input script command makes Quest wait for input, and the text goes into a variable called result. It then tests if the answer is correct using the IsRegexMatch function. A Regex is a pattern to match against, and in this case will match either "2" or "two" (it also ignores case, so will match "Two" and "TWO").

commented May 16 by stevem (1 point)
Thanks u very much!
0 votes
answered May 13 by hegemonkhan (161 points)
edited May 13 by hegemonkhan

the quest wiki:

http://docs.textadventures.co.uk/quest/

this is a bit more than what you're asking for, but it does a good job for showing~guiding you through it:

http://docs.textadventures.co.uk/quest/guides/character_creation.html

generally you want:

.1. the 'msg' Script for asking your question:

in code:

http://docs.textadventures.co.uk/quest/scripts/msg.html

msg ("One plus One equals what?")

or, in the GUI~Editor:

run as script -> add a~new script -> output -> 'print a message' Script -> [MESSAGE]: for text only, or [EXPRESSION]: for text+VARIABLES

.2. the 'get input' Script for getting the input of the person playing the game:

in code:

http://docs.textadventures.co.uk/quest/scripts/get_input.html

(using within a Function, as an example)

    <function name="question_1_function">
      msg ("One plus One equals what?")
      get input {
        // the 'get input' Script automatically (hidden from you) sets the built-in Variable 'result' to the person's, who's playing the game, input: result = your_typed_in_input_during_game_play
        // your scripts
      }
    </function>

or in the GUI~Editor:

run as script -> add a~new script -> output -> 'get input' Script

.3. your scripts:

http://docs.textadventures.co.uk/quest/scripts/if.html
http://docs.textadventures.co.uk/quest/scripts/msg.html

    if (result = "2" or result = "two") {
      msg ("Correct, good job!")
    } else {
      msg ("That's incorrect, try again.")
      // loop~repeat this script block
    }

so in full code example:

    <function name="question_1_function">
      msg ("One plus One equals what?")
      get input {
        if (result = "2" or result = "two") {
          msg ("Correct, good job!")
        } else {
          msg ("That's incorrect, try again.")
          question_1_function
        }
      }
    </function>

or in the GUI~Editor:

run as script -> add a~new script -> scripts -> 'if' Script -> [EXPRESSION]: if you want to write out the code yourself, or [whatever]: I don't know the GUI~Editor's options and etc well.

-> then, -> add a script -> output -> 'print a message' Script -> [MESSAGE] -> Correct, good job!

else,

-> add a script -> output -> 'print a message' Script -> [MESSAGE] -> That's incorrect, try again.

(for my example only): add a script -> ??? -> 'call function' Script -> for Function name: question1function, Parameters: (leave blank, don't add any in)

in your post, you say: "for example when entering a room, it asks the question", which would be done via:

in the GUI~Editor:

'whatever the room name' (Room) Object -> 'whatever it is called or is' Tab -> 'on enter room' text box -> [run as script] -> put in the entire scripting above (but ignore my use of putting the scripts into a Function, unless you want to use a Function ~ ask me if you want to do this, and don't know how) goes into this 'on enter room' now-script-instead_of-text box.

if you want better code, then you got to use Commands and~or Functions, doing 'concatenation', as an example:

http://docs.textadventures.co.uk/quest/elements/function.html (scroll down ~ look at the: 'working example' bottom section)

commented May 13 by hegemonkhan (161 points)
edited May 13 by hegemonkhan
p.s.
for:
http://docs.textadventures.co.uk/quest/scripts/ask.html
or-as: the 'ask' Script in the 'ask and tell' Tab in the GUI~Editor is a bit misleading, as it's not a general purpose Script for asking any question you want, but rather it is ONLY for asking a boolean~binary~'yes-no'~'true-false' (yes:true or no:false) question.
so the 'ask' Script would be for a question like this:
Are you a male?
(the answer is either yes:true or no:false)
but NOT for:
What is your name?
--------------
P.S.S.
more useful links for you:
http://docs.textadventures.co.uk/quest/guides/ (guides)
http://forum.textadventures.co.uk/viewforum.php?f=10&sid=e59ca4005a120ae471ae98ac0c8d0a66 (the quest forum ~ lots of help here)
http://forum.textadventures.co.uk/viewforum.php?f=18 (more guides: Libraries and Code Samples)
http://docs.textadventures.co.uk/quest/tutorial/ (the tutorial, very useful to go through fully, even if boring~simple, as it gets you familiar with quest and with coding~if logic)
http://docs.textadventures.co.uk/quest/upgrade_notes.html (upgrade~version notes~history ~ the 'change logs' for quest. Very useful link)
http://docs.textadventures.co.uk/quest/asl_requirements.html
http://docs.textadventures.co.uk/quest/elements/ (the main things or 'physical things' in quest)
http://docs.textadventures.co.uk/quest/types/ (the Attributes)
http://docs.textadventures.co.uk/quest/functions/ (quest's 'code bible' 1: the Functions, in categorical order)
http://docs.textadventures.co.uk/quest/functions/index_allfunctions.html (quest's 'code bible' 1: the Functions, in alphabetical order)
http://docs.textadventures.co.uk/quest/scripts/ (quest's 'code bible' 2: the Scripts)
commented May 16 by stevem (1 point)
Thanks you very much !

## Related questions

- How do I use the create exit command properly in Quest
- How do I make verbs synonymous for only certain objects in Quest 5.6.1?
- In a Gamebook, how do I fix that the text processor is not working properly on my version of Quest (I think)?
- How do I work with lists in Quest?
- In Quest, how do I send an integer from javascript to Quest and keep it an integer?

...