User Question
Dmcg12
11 Dec 2012, 22:10Hey all again,
After my last topic i've come on leaps and bounds with the game
but run into another problem that i'm not sure how to overcome.
I want to ask the user a question , in my case, i want to ask the user a question that only has one answer, and if that answer is wrong, they are told they are wrong and they just stay in place until they can answer the question correctly, i use the question script already built into quest , but it dosn't allow for manual input as i want the player to manually type their answer, and i have no idea how to go about solving it
Any advice would be appreciated?
After my last topic i've come on leaps and bounds with the game

I want to ask the user a question , in my case, i want to ask the user a question that only has one answer, and if that answer is wrong, they are told they are wrong and they just stay in place until they can answer the question correctly, i use the question script already built into quest , but it dosn't allow for manual input as i want the player to manually type their answer, and i have no idea how to go about solving it

Any advice would be appreciated?

jaynabonne
11 Dec 2012, 23:58You can use "get input" to read the next line of input directly. Then you can see what the value is and go from there (e.g. print the "wrong" message and go back to another get input, or proceed on if correct).
The trickiest part is looping back. But if you put the "get input" sequence into a function, then you can just have it invoke itself again if the input is wrong within the "get input" result script.
If that doesn't make sense, ask.
The trickiest part is looping back. But if you put the "get input" sequence into a function, then you can just have it invoke itself again if the input is wrong within the "get input" result script.
If that doesn't make sense, ask.

The Pixie
12 Dec 2012, 12:43Instead of
you might want to do
That will match any part of the string the player types, and ignore case (would work better with a longer answer than above though!).
if (player.answer1 = result) {
you might want to do
if (IsRegexMatch (player.answer1, result)) {
That will match any part of the string the player types, and ignore case (would work better with a longer answer than above though!).
HegemonKhan
13 Dec 2012, 05:36My Full (Amatuerish) Guide Completed:
Any of the '...' (single quotations) are NOT to be typed in. they're just used by me to highlight my example stuff that I'm using.
Same with the (....) ~ (parenthensis), they're to NOT to be typed in as well.
the [...] reresent the options that are the "box seleting click-pull-down options"
the -> (arrows) on the far left in front of the lines, represent indentation. I show this as it matters, but I can't explain this very well, as I don't fully understand enough to try to explain it myself.
The below is a step by step guide to setting this up, just follow along each thing [separated by the -> (arrows) ] I say to do.
GUI (user-friendly with the buttons-options) Mode:
First, for my example, we need to do this:
Objects -> Player -> Attribute Tab -> Attributes (the bottom box) -> Add -> answer1 -> [String] -> (the correct answer, such as, 'HK'. This is needed-used by-in a later coding step below)
Second, is to create the Call Funcion Script at the location that you want your Question to be at:
for my example, I choose to use this as my location for your question:
Objects -> Game -> Script Tab -> Start Script
but you can do this at any location you want to do so, as you simply need to do this:
Add New Script -> Scripts -> Call Function -> question1 -> With Parameters -> (you don't need to add anything here; so leave it blank)
Creating the Function, the start of the main script coding:
Functions -> Add -> question1
Functions -> question1 -> Name: question1 -> Return Type: [None] -> Parameters: (Don't add any; leave blank) -> Script (the bottom box) -> (continued below)
(by setting up a function, we can give the entire script block (below) for it, the designation of, 'question1', which can and will be 'called upon, used, or brought up' whenever and-or wherever a 'Call Function' Script has 'question1' typed into it. So, thus by making the coding script block a function, then we only need to do so once, and can simply use the 'Call Function' Scripts using the label we gave it, in this case as 'question1', to use it, at and in, that location, instead of re-creating the entire script block)
And now we get into the actual main scripting:
Add New Script (continued from above) -> Output -> Print A Message [Message] -> (explain what is going on, such as, 'To proceed, you must answer the question correctly' )
Add New Script -> Output -> Print A Message [Message] -> (your question to them, such as, 'What is my name? Answer: HK' )
Add New Script -> Output -> Get Input -> , then run script:
-> Output -> Print A Message [Expression] -> result
-> Add New Script -> Scripts -> If... : -> [Object Attribute Equals] -> Object: -> [object] -> [player] -> Attribute -> answer1 (this is where that very first step comes into use) -> result (this is what the person has typed in, made possible by the 'Get Input' script above)
->-> Then: -> Output -> Print A Message [Message] -> (type in something letting the person know they got the question correct, such as, 'You got the answer right, you may proceed' )
->-> Add Else: -> Output -> Print A Message [Message] -> (type in something letting the person know they got the question wrong, such as, 'Wrong answer, try again' )
->-> Add Else: -> Add New Script -> Scripts -> Call Function -> Call Function -> question1 -> With Parameters: (you don't need to add anything here; so leave it blank)
(this 'Call Function' Script ending line will restart this entire script coding block, designated as the function 'question1', again, as the person got the question wrong)
Code View Mode:
(you can toggle this mode on and off, it's a paper-note-looking button, called 'Code View', on the toolbar at the top, on the right side, between the 'Play' and 'Help' buttons)
this is the same (well, the REAL) stuff, as is and that is, going on with the GUI, but because of that, it's hard to match up the GUI with the Code View, due to seeing the GUI's buttons as their actual codings in the Code View. But, aside from this, it's a good way to learn more about the coding.
Any of the '...' (single quotations) are NOT to be typed in. they're just used by me to highlight my example stuff that I'm using.
Same with the (....) ~ (parenthensis), they're to NOT to be typed in as well.
the [...] reresent the options that are the "box seleting click-pull-down options"
the -> (arrows) on the far left in front of the lines, represent indentation. I show this as it matters, but I can't explain this very well, as I don't fully understand enough to try to explain it myself.
The below is a step by step guide to setting this up, just follow along each thing [separated by the -> (arrows) ] I say to do.
GUI (user-friendly with the buttons-options) Mode:
First, for my example, we need to do this:
Objects -> Player -> Attribute Tab -> Attributes (the bottom box) -> Add -> answer1 -> [String] -> (the correct answer, such as, 'HK'. This is needed-used by-in a later coding step below)
Second, is to create the Call Funcion Script at the location that you want your Question to be at:
for my example, I choose to use this as my location for your question:
Objects -> Game -> Script Tab -> Start Script
but you can do this at any location you want to do so, as you simply need to do this:
Add New Script -> Scripts -> Call Function -> question1 -> With Parameters -> (you don't need to add anything here; so leave it blank)
Creating the Function, the start of the main script coding:
Functions -> Add -> question1
Functions -> question1 -> Name: question1 -> Return Type: [None] -> Parameters: (Don't add any; leave blank) -> Script (the bottom box) -> (continued below)
(by setting up a function, we can give the entire script block (below) for it, the designation of, 'question1', which can and will be 'called upon, used, or brought up' whenever and-or wherever a 'Call Function' Script has 'question1' typed into it. So, thus by making the coding script block a function, then we only need to do so once, and can simply use the 'Call Function' Scripts using the label we gave it, in this case as 'question1', to use it, at and in, that location, instead of re-creating the entire script block)
And now we get into the actual main scripting:
Add New Script (continued from above) -> Output -> Print A Message [Message] -> (explain what is going on, such as, 'To proceed, you must answer the question correctly' )
Add New Script -> Output -> Print A Message [Message] -> (your question to them, such as, 'What is my name? Answer: HK' )
Add New Script -> Output -> Get Input -> , then run script:
-> Output -> Print A Message [Expression] -> result
-> Add New Script -> Scripts -> If... : -> [Object Attribute Equals] -> Object: -> [object] -> [player] -> Attribute -> answer1 (this is where that very first step comes into use) -> result (this is what the person has typed in, made possible by the 'Get Input' script above)
->-> Then: -> Output -> Print A Message [Message] -> (type in something letting the person know they got the question correct, such as, 'You got the answer right, you may proceed' )
->-> Add Else: -> Output -> Print A Message [Message] -> (type in something letting the person know they got the question wrong, such as, 'Wrong answer, try again' )
->-> Add Else: -> Add New Script -> Scripts -> Call Function -> Call Function -> question1 -> With Parameters: (you don't need to add anything here; so leave it blank)
(this 'Call Function' Script ending line will restart this entire script coding block, designated as the function 'question1', again, as the person got the question wrong)
Code View Mode:
(you can toggle this mode on and off, it's a paper-note-looking button, called 'Code View', on the toolbar at the top, on the right side, between the 'Play' and 'Help' buttons)
<asl version="520">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Testing Game Stuff">
<gameid>cd102f9d-370a-4bda-b6ea-ca42288f619c</gameid>
<version>1.0</version>
<start type="script">
question1
</start>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="defaultplayer" />
<answer1>HK</answer1>
</object>
</object>
<function name="question1">
msg ("To proceed, you must answer the question correctly")
msg ("What is my name? Answer: HK")
get input {
msg (result)
if (player.answer1 = result) {
msg ("You got the answer right, you may proceed")
}
else {
msg ("Wrong answer, try again")
question1
}
}
</function>
</asl>
this is the same (well, the REAL) stuff, as is and that is, going on with the GUI, but because of that, it's hard to match up the GUI with the Code View, due to seeing the GUI's buttons as their actual codings in the Code View. But, aside from this, it's a good way to learn more about the coding.
Dmcg12
12 Feb 2013, 01:30Sorry for the late reply, had too much of a break during the holidays 
Just wanted to say a major thanks to all your replies, i got it working perfectly now, game is starting to really come together with everyones help, i'll be sure to put it online for everyone once i'm done , thanks a lot

Just wanted to say a major thanks to all your replies, i got it working perfectly now, game is starting to really come together with everyones help, i'll be sure to put it online for everyone once i'm done , thanks a lot


guzmere
13 Feb 2013, 09:08Forgive me for this but I'm sure I read somewhere that (Get Input) is being deprecated or was it ( Set variable, (player input)) or am I confusing it with something else. Terry
Happy adventuring 


Alex
13 Feb 2013, 11:07The "get input" script command is being used here, which is the recommended way of getting input from the player as it doesn't pause a script. http://quest5.net/wiki/Get_input
It's the old "GetInput" function which is removed as of Quest 5.4: http://quest5.net/wiki/GetInput
Confusing perhaps but maybe less confusing than calling it something different.
It's the old "GetInput" function which is removed as of Quest 5.4: http://quest5.net/wiki/GetInput
Confusing perhaps but maybe less confusing than calling it something different.

guzmere
13 Feb 2013, 11:44Hi Alex forgive me for being thick but is it still ok to use the (set var, (player input)). I understnd that.Thanks Terry
Happy adventuring 


Alex
13 Feb 2013, 12:20The "player input" option is removed from the "set" dropdown in v5.4, as that uses the GetInput function.
To set an attribute to the player input, use something like this...
To set an attribute to the player input, use something like this...
msg ("Please enter your name:")
get input {
player.displayname = result
}

guzmere
13 Feb 2013, 12:35Ok I understand that now, thanks Alex
Happy Adventuring 

