I've set an NPC object that asks a yes/no question after the player speaks to it. However, I can't figure out how to program to respond differently when the chooses No
I would:
EDIT
If you want to see it as code, here is a sample "game" for using the get input/switch combo script for yes and no questions. The first room allows the player to ignore the yes or no with a default statement and the second room prevents avoiding the question using a call function script. You can open a new file and copy-paste this over the existing code if you want to see it in the GUI.
<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Get Input & Switch Yes or No Example">
<gameid>ce1d9d52-41f8-45d5-99b6-6b576b68a206</gameid>
<version>1.0</version>
<firstpublished>2017</firstpublished>
<attr name="feature_asktell" type="boolean">false</attr>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
<object name="Magoo">
<inherit name="editor_object" />
<speak type="script"><![CDATA[
msg ("\"Hey, you! Do you like my new hat?\"")
get input {
switch (LCase(result)) {
case ("yes","y","yea","yep","sure","affirm","ye","ya") {
msg ("\"Why,\" Magoo says thoughtfully, \"Thank you so much!\"")
}
case ("no","nope","nay","n","na","negative") {
msg ("\"Ouch,\" Magoo responds. \"That cuts me deep.\"")
}
default {
msg ("\"You have failed to answer a simple 'yes' or 'no' question with gibberish I do not understand,\" replies Magoo. <br/><br/>Perhaps you should speak to him again...")
}
}
}
]]></speak>
<look>Magoo is standing here looking sharp in his new hat.</look>
<usedefaultprefix type="boolean">false</usedefaultprefix>
<alias>Mr. Magoo</alias>
</object>
<object name="hat">
<inherit name="editor_object" />
<scenery />
<look>It's one of the ugliest hats you have ever seen.</look>
</object>
<exit alias="south" to="room2">
<inherit name="southdirection" />
</exit>
</object>
<object name="room2">
<inherit name="editor_room" />
<object name="Mr_Mouse">
<inherit name="editor_object" />
<alias>Mr. Mouse</alias>
<look>He is a man, but he looks an awful lot like a mouse.</look>
<speak type="script">
msg ("Mr. Mouse wiggles his little nose and says, \"Do you have any cheese?\"")
mister mouse convo
</speak>
<usedefaultprefix type="boolean">false</usedefaultprefix>
</object>
<exit alias="north" to="room">
<inherit name="northdirection" />
</exit>
</object>
<function name="mister mouse convo"><![CDATA[
get input {
switch (LCase(result)) {
case ("yes","y","yea","yep","sure","affirm","ye","ya") {
msg ("\"Fabulous!\" Mr. Mouse says. He reaches out his hands eagerly waiting...<br/><br/>But as he sees you have no cheeese he sighs and looks upset.")
}
case ("no","nope","nay","n","na","negative") {
msg ("\"Well,\" Mr. Mouse says, \"That's too bad because I have a great gift for anyone who brings me cheese.\"")
}
default {
msg ("\"Huh? I did not understand you. I said... Yes or No... Do you have any cheese?\"")
mister mouse convo
}
}
}
]]></function>
</asl>
The other option is to use menus. I could help with that too if you choose that route, but it's not my cup-o'-tea.
Ask if you have any questions.
Your sample code will result in an exact answer...
Otherwise, you will get sample answers that may or may not work for what you are looking for...
XanMag... I read you code, and thought the player was saying it was "garb" (clothing)... Then realize she was interrupted... ( lol!)
"Switch"... Yea, that would be the easiest way to handle player responses... (and expandable later if needed)
Or a [yes,no] reply...
(not sure the code, but I've seen it here... somewhere...)
Like this:
show menu ("Your gender?", Split ("Male;Female", ";"), false) {
player.gender = result
}
This will create a menu response that the player can only select Male or Female.
(Altho, you will want to change the question and "yes;no" for your answer,
then do a:
If(result="yes"){
// the yes code...
} else {
// the no code
}
Haha!! You made me question my sanity, DL! I went back and made two samples in a new file!
Here is also a good place to check...
http://docs.textadventures.co.uk/quest/
example:
http://docs.textadventures.co.uk/quest/scripts/ask.html
http://docs.textadventures.co.uk/quest/functions/ask.html
// popup window menu during game play:
ask ("Are you a male?") {
// quest automatically (hidden from you) changes your selection of 'yes' to 'true' or 'no' to 'false', and stores it into the 'result' Variable: 'result = true' or 'result = false'
if (result) { // if true
player.sex = "male"
} else { // if false
player.sex = "female"
}
}
// ------------------------------------------------------
// or, "in-line" (clickable hypertext in the left side's big text box area during game play) menu:
Ask ("Are you a male?") {
// quest automatically (hidden from you) changes your selection of 'yes' to 'true' or 'no' to 'false', and stores it into the 'result' Variable: 'result = true' or 'result = false'
if (result) { // if true
player.sex = "male"
} else { // if false
player.sex = "female"
}
}
using online quest
and code makes less sense to me, so you really don't need to put it up here
You can do this, and there will be a 'YES or NO' pop-up window:
UPDATE: This was initially incorrect, but has been fixed now. (Sorry cheshiretiger! And thanks, hegemonkhan! *)
And here's the doc regarding that one:
http://docs.textadventures.co.uk/quest/scripts/ask.html
NOTE: I just set this example up to trigger this when SPEAK TO NPC is the command.
If you don't want the pop-up window, click the Code View
button on the very bottom, and change that very first A (in 'ask') to a lower case a
for a pop-up window, and change it to a capital A
for a regular text hyperlink.
Not working. No pop up window. when in game to test, it says Error compiling expression '(result)'
just remove the parenthesis from your uses of '(result)' in the GUI/Editor, like so:
from: (result)
to: result
Richard accidentally put in the parenthesis, for the GUI/Editor example, and thus the error:
as there is no built-in '(result)' Variable VARIABLE; there's the built-in 'result' Variable VARIABLE
when using the GUI/Editor and its script option drop-downs and/or text boxes, it handles the code syntax for you.
but if you were writing directly in code, then you'd need to put in the code syntax.
GUI/Editor:
if [EXPRESSION] result
-> then, -> add new script -> 'WHATEVER' Script(s)
VS (these are the same thing)
directly in code:
if (result) {
// scripting
}
I'm sorry about that cheshiretiger! (I'll blame it on the online editor, if no one objects...)
I edited the post1 to avoid confusing anyone else!
By the way,
Thanks hegemonkhan!