Asking player to input a specific number/phrase
bitterkarella
06 Aug 2016, 04:30Hi! I'm trying to create a puzzle where the player finds a phone number and later has to use a telephone to dial that number. Basically I was trying to figure out if there's a way to ask the player to input some information and then, if the correct information is entered, run a script.
I'm not sure if this is even possible to do, since I haven't seen anything in Quest that suggests it would be, but thought I'd ask. Thanks for your help!
XanMag
06 Aug 2016, 05:12Here is how I would do it.
- Create your telephone object.
- On the features tab, tick the box that says use/give.
- Click on the use/give tab.
- Under the section 'use (on its own)', select run script from the drop down menu.
- Choose a print message script and print something like the following -
"You pick up the phone. Now, what number would you like to call?"
I used <.b> before the word 'what' and <./b> after the question mark (without the periods) to print this part of the message in bold. I do this for every situation where the player is requested to answer a question. It kind of forces the player to realize that whatever is entered next will be answering the question. Of course, this is optional (just a personal preference).
- Add a Get Input script.
- Under the 'Then' section of this script add a 'Switch' script.
- In the space next to 'Switch:' type the following - result
- In the 'Cases:' section below, click on '+ Add'
10a. Type this in the 'case expression' that pops-up - "1234567","123-4567","123.4567","123 4567","123 - 4567","123 . 4567"
10b. You do want to type this with quotes and commas. If you don't, it will not work. You will obviously want to put your own number in each space between the quotes. You will also want to think of any variation that the player may try to type in that is correct. In 10a above, each case is slightly different but probably should be viewed as acceptable in dialing the number. - After clicking 'okay' when finished typing in your case expressions, a new window will pop-up. Here, enter whatever script(s) you want to run. In the code below, I simply printed a message, but obviously you will script whatever you want to happen here after successfully calling the right number.
- In the default section of this same 'switch' script, run whatever script(s) you want whenever a wrong number is dialed.
- As a word of advice, you may want to add cases for some commonly dialed numbers like 911, 411, 511, 0, etc to add to the realism of the phone.
Here is the code for the telephone if seeing it in this fashion is more helpful.
msg ("You pick up the phone. Now, <b>what number do you want to call?</b>")
get input {
switch (result) {
case ("1234567","123-4567","123.4567","123 4567","123 - 4567","123 . 4567") {
msg ("You have successfully called your friend.")
}
default {
msg ("You dial that number and wait. After ringing a few times, you hear a robotic operator say \"The number you have dialed is no longer in service or has been disconnected. Please check the number and dial again.\"")
}
}
}
That should do it, right? If you have any questions, please feel free to ask. Good luck!
EDIT: You could also add a verb 'dial' to the phone and paste this same code under the dial verb in addition to putting it in the use (on its own) script. That way 'dial phone' would also illicit a proper/reasonable response.
As a side note, if you haven't done this already, I would go to the object tab of the telephone and add 'phone' to the other names section. =)
XanMag
bitterkarella
06 Aug 2016, 06:12Oh wow, that worked perfectly! Thanks so much for the help! :)
hegemonkhan
06 Aug 2016, 06:23if you want the person playing the game to type in (in the text-command box at bottom of screen) their phone number input, you can do that via using the 'get input' Script. If you wanted to have actual Objects and their Verbs as the 0-9 numbers on your 'phone' Object to be clicked on, that's a different implementation (let me know if this is the case). Here's a good example guide on using the 'get input' Script (though it's used for something else: character creation, in the guide/link below):
http://docs.textadventures.co.uk/quest/guides/character_creation.html
hidden from you, it sets: result = your_typed_in_input
which you can then use that 'result' Variable for whatever you want.
for your interest, a simple example:
get input {
if (result = "81927") {
msg ("ding ding ding, that's the correct password!")
} else {
msg ("Wrong password, you lose the game!")
msg ("GAME OVER")
finish
}
}
the other way to get typed-in input by the person playing the game is via a Command.