Help with yes/no questions

Unexpected128
Good afternoon! I've recently downloaded Quest, and am learning its basics to make a simple game to share with my friends.
I've tried adding a yes/no question to my game, and tried following the steps in this page: http://docs.textadventures.co.uk/quest/ ... tion1.html
However, Quest doesn't show the "player answers Yes to" script for me. I can only use the "ask a question" script and add the text for the question, but the only thing after it is "after choosing, run script:", and I can't choose to make the next script different depending on if the answer is yes or no. Any help?

Silver
If I wanted to do a yes / no question I'd probably turn off the command bar and present them as links.

You can do this though:

msg ("this is a question that requires a yes or no answer.")
Get input {
If (result = "yes") {
// run yes script
} else if (result = "no") {
// run no script
} else {
// something else happens
}
}


Did I mess that up, HK?

The Pixie
I would guess that page was for an earlier version of Quest. Try using the "Ask question" option, which looks essentially the same (except in play you get hyperlinks instead of a dialogue box).

If you are happy to look at the code view, look at the "ask" function (script command).
http://docs.textadventures.co.uk/quest/scripts/ask.html

The Pixie
Silver, what ask does is a kind of validation. It ensures that you the creator will only have to handle "yes" or "no". The problem with using get input is that you have to account for "y" or "YES" or "sure" or "i don't know" etc.

Silver
That's interesting. I had to do:

if (result = "Yes") or (result = "YES") or (result = "yes") or ( etc etc)


and you can't think of everything. I didn't know about ask, tbh.

The Pixie
Another trick, do this when you use get input:
if (LCase(result) = "yes") ...

HegemonKhan
@Silver:

you basically crafted the built-in 'ask' Function, hehe.

Silver's 'get input' code:

(no annoying popup window: why you'd use this 'get input' method, hehe)

msg ("this is a question that requires a yes or no answer.")
Get input {
If (result = "yes") {
// run yes script
} else if (result = "no") {
// run no script
} else {
// something else happens
}
}


vs

Quest's built-in 'ask' Function (uses a popup window, like 'show menu' does) code:

ask ("this is a question that requires a yes or no answer.") {
// you select 'yes' or 'no' from the popup window
// quest's 'ask' Function does this automatically (hidden from you): yes -> true
// quest's 'ask' Function does this automatically (hidden from you): no -> false
if (result = true) {
// script1
} else if (result = false) {
// script2
}
}


this can be shortened to (what Pixie links to in his~her post):

ask ("this is a question that requires a yes or no answer.") {
if (result) {
// script1
} else {
// script2
}
}


------------

@Silver:

here's my own slightly more thorough~advanced version:

<function name="custom_ask_function">
msg ("Do you want to live?")
msg ("(Type in the number of your choice)")
DisplayList (global_data_object.yes_or_no_stringlist, true)
get input {
if (result = "1") {
msg ("Doh! Fine, live, then, grr")
wait {
ClearScreen
}
} else if (result = "2") {
msg ("Yessss! Muwuhaha! Die!")
wait {
ClearScreen
}
} else {
ClearScreen
custom_ask_function
}
}
</function>

<object name="global_data_object">
<inherit name="editor_object" />
<attr name="yes_or_no_stringlist" type="simplestringlist">yes;no</attr>
</object>


actually, I could make this a bit more advanced, using a String Dictionary... hehe...

(but that's the limit of my level of coding, as I don't know how to do whatever is more advanced~better than in this exampe, of using a String Dictionary, sighs)

-----------

@unexpected28:

quest's 'ask' Function isn't that clear on how it works (it took me awhile to figure it out myself, argh!)

in the GUI~Editor:

turn~toggle on the 'ask~tell' Tab, as one of the settings of the 'game' Game Object, or as one of the settings for the specific Object you want the 'ask' Function to be for.

for the specific Object, click on the 'ask~tell' Tab, and set up the 'ask' Function:

'whatever' Object -> 'ask~tell' Tab -> 'ask' Function -> type in your message~question ->

run as script -> add a~new script -> scripts -> 'if' Script -> [EXPRESSION] -> type in: result
-> then, -> add a~new script -> (select a script)
else,
-> add a~new script -> (select a script)

in Code:

ask ("this is a question that requires a yes or no answer.") {
if (result) {
// script1
} else {
// script2
}
}

The Pixie
Just realised there are two different functions.

ask (all lower case) will bring up a dialogue box (and is technically a script command).
Ask (capitalised) will do it with hyperlinks.

There is not much difference in how you code, except that if you use local variables in the block with Ask you will get an error, "Unknown object or variable" (if you do not know what that means, then it will probably not be a problem).

HegemonKhan
and I just learned from your posts that there's a 'hyperlink' (upper case) one, laughs. I just knew of the 'popup window' (lower case) one, lol.

looks like both me and silver created our own Functions, as we don't like the 'ask' Function's popup window, not knowing that there's the other 'ASK' Function, which uses hyperlinks, instead of a popup window. DOH! (well not wasted effort, our custom 'ask' functions are useful still too, hehe).

Unexpected128
Many thanks for all the replies! Coding is very confusing to me, but by pasting the example code on my game and checking how it was shown in the GUI, I understood that I had to set "expression" to "result" for it to be what happens with the "yes" reply :D Wow, I'd never have figured this out by myself!

HegemonKhan
You'll at some point get around to learning to code (hopefully), as it seems you already are moving towards it (switching between code view mode and the GUI~Editor mode, to see how the code converts into how it is done~looks in the GUI~Editor), hehe.

Silver was totally against coding... now he~she loves it, probably not going back much to the GUI~Editor anymore, just like me (as I too came into quest not knowing anything at all about coding, and but used quest to learn to code, to get where I'm at today: still a noob at coding, but I've come a long way, and Silver is making good code progress now too. If you want to learn to code, quest is really awesome for it). Code is indeed very scary at first, but as you slowly start to learn it, it's really not that difficult (it's really just a lot of algebra: algebraic substitutions, but coming up with creative~advanced code designs, that's hard, lol. But just the coding itself, isn't really as bad as it certainly does seem for people new to code). The GUI~Editor is great, but once you can code, you don't have much more need for it anymore.

-------

try leaving the bracket choice as [EXPRESSION], and then in the text box, type in: result, see below

if -> [EXPRESSION] -> result

and see what happens ;)
(it's the exact same thing)

how is it in the GUI~Editor (too lazy to fire up quest to find out myself, lol) ???, something like this:

if -> [VARIABLE~whatever the label choice here] -> [RESULT]

or

if -> [RESULT]

???

Silver
The Pixie wrote:Another trick, do this when you use get input:
if (LCase(result) = "yes") ...


I never thought of that. Good tip.

Silver
HegemonKhan wrote:and I just learned from your posts that there's a 'hyperlink' (upper case) one, laughs. I just knew of the 'popup window' (lower case) one, lol.

looks like both me and silver created our own Functions, as we don't like the 'ask' Function's popup window, not knowing that there's the other 'ASK' Function, which uses hyperlinks, instead of a popup window. DOH! (well not wasted effort, our custom 'ask' functions are useful still too, hehe).


Well mine happens with the typewriter effect so I was getting the code to work with that. I didn't know about either ask or ASK.

Silver
HegemonKhan wrote:You'll at some point get around to learning to code (hopefully), as it seems you already are moving towards it (switching between code view mode and the GUI~Editor mode, to see how the code converts into how it is done~looks in the GUI~Editor), hehe.

Silver was totally against coding... now he~she loves it, probably not going back much to the GUI~Editor anymore, just like me (as I too came into quest not knowing anything at all about coding, and but used quest to learn to code, to get where I'm at today: still a noob at coding, but I've come a long way, and Silver is making good code progress now too. If you want to learn to code, quest is really awesome for it). Code is indeed very scary at first, but as you slowly start to learn it, it's really not that difficult (it's really just a lot of algebra: algebraic substitutions, but coming up with creative~advanced code designs, that's hard, lol. But just the coding itself, isn't really as bad as it certainly does seem for people new to code). The GUI~Editor is great, but once you can code, you don't have much more need for it anymore.

-------

try leaving the bracket choice as [EXPRESSION], and then in the text box, type in: result, see below

if -> [EXPRESSION] -> result

and see what happens ;)
(it's the exact same thing)

how is it in the GUI~Editor (too lazy to fire up quest to find out myself, lol) ???, something like this:

if -> [VARIABLE~whatever the label choice here] -> [RESULT]

or

if -> [RESULT]

???


Yeah code used to give me the fear. What changed was there's some things that can only be done with code such as html. And there's that much being handled in the first room of my game that it just looks an absolute mountain in gui view now, click code view and it suddenly looks all neat and manageable. My gripe now is that scripts get displayed in the gui as standard and so I have to keep clicking code view all the time. Is there any way to change that?

I'm a he btw.

jaynabonne
Just to throw in another pair of coppers... An alternative to the "get input" route is to use a simple menu. It has the advantage that Quest will validate the input for you (so you don't need to do all the "if yes" sort of thing), and the user will have nice links to click on, but the downside is that they will be typing things like "1" or "2" for the answers instead of "y", "yes" etc. That might be a deal-breaker or not.

One way to mitigate the latter issue is to phrase the question in a way that doesn't seem so yes-no-ish, where entering numbers might be considered a benefit for the player. For example, instead of:

Is this all correct?
* Yes
* No

you could phrase it:

What would you like to do?
1. Continue
2. Go back and make changes

It opens up interesting possibilities that the "get input" approach might not so easily support So... an alternative that may or may not be applicable. :)

HegemonKhan
I really need to learn all of the 'inline~hyperlink~text processor' things in quest... as I could use those built in things instead of making my own, due to not liking the popup windows in my games.

Silver
The text processor is the easiest thing.

Create a command that houses a script. Or create a command that houses a function. The command is called fight but you want to say it as attack in the description. Then it's this:

msg("The Goblin backs away slightly and its eyes pierce you. You feel you could {command:fight:attack} him now or you could {command:something:else} away from him.")


Clicking the attack link will run the fight command. but it will be displayed as attack in the description string.

HegemonKhan
so is it like this then:

{command:command_name:command_alias}

example:

{command:fight:battle}

???

hmm... am I going to have to make separate commands for: attack (weapon~physical), magic, item, escape

or can those be selected within the inline command ???

as, my combat code's structure is this:

Command:

fight_command
-> attack
-> magic
-> item
-> escape

as:

do you want to {command:fight:attack} or {command:fight:magic} or {command:fight:item} or {etc etc etc}

or is that 3rd entry, just the 'alias', and not a 'subchoice' within your comamnd ???

Silver
{these:three:entries}

The first is command.
The second is the name of the command. It can be anything. It can be ghghghg. But that is the command that will run. The third is the word you want the link to say.

So, saying

msg("you have entered a room. Would you like to {command:ghghghg} the door}")


Will read as:

you have entered a room. Would you like to ghghghg the door?

It will run the ghghghg command but will look crap. So you do this:

msg("you have entered a room. would you like to {command:ghghghg:open} the door")


it will do the same as before. But will read:

you have entered a room. would you like to open the door?

jaynabonne
You can either create a separate command for each or pass parameters to a single command or some combination of the two. The "command_name" part is actually a full command. It can be something like "fight" or "Combat_Attack" (both single commands) or something more complex like "Combat attack", where the command has pattern "Combat #text#" and you then have to check the text param to see what subcommand you're executing. Like:

You can:
{command:combat fight:Attack}
{command:combat magic:Use magic}
{command:combat item:Use item}
{command:combat escape:Escape}

This shows:

You can:
Attack
Use magic
Use item
Escape

and if you click "Attack" it sends the command "combat fight". The "combat" command can then compare text to "fight" to handle that particular area. One way or another you need to have unique commands for each case.

You can also do something like this:

  <command name="Dungeons_DoScriptCmd">
<pattern>DoScript #text1# #text2#;DoScript #text1#</pattern>
<script>
<![CDATA[
// We just executed a command. Clear the screen.
Dungeons_NewScreen()
// text = object:attribute parameters
// text2 = parameter string (param1,param2,...)
source = Split(text1, ".")
object = StringListItem(source, 0)
attribute = StringListItem(source, 1)
if (not IsDefined("text2")) {
text2 = ""
}
args = Split(text2, ",")
params = NewDictionary()
argnum = 1
foreach (arg, args) {
dictionary add(params, "arg"+argnum, arg)
argnum = argnum + 1
}
//msg("object = " + object + ", attribute = " + attribute + ", params = " + params)
do (GetObject(object), attribute, params)
]]>
</script>

This command takes command text like "DoScript player.attack", where it will then invoke the script "attack" on the player object, or even something like "DoScript shop.buy axe", where you have an object named "shop" with a script named "buy". It will be called with a parameter named "arg1" set to "axe". Basically, the command line can be as complicated as you wish to parse.

A command with the latter script would be like: {command:DoScript combat.attack:Attack}, which would invoke the "attack" script on the "combat" object.

HegemonKhan
your later example is a bit advanced for me right now, my brain still has difficulty with this parsing~advancing scripting stuff (as I'm still trying to understand the string parsing of the command scripting in Pixie's Level Library), so for your former, how would you check for the command's pattern? Can the command's pattern be within the text string (and is it within the {inline command} or outside of it) ??

wait... I think I get it (I looked at your post again):

pattern: combat #text#
.........................\........\
{command:fight:combat #text#} or is it {command:fight:combat} + #text#

example:

[command:fight:combat orc} or is it {command:fight:combat] orc

----

but whichever the case (if one of them is even correct, lol), how do I then.. get the parameters to check them with the pattern and the scripting, or is that done automatically for me (via the hyperlink for the left syntax) ???

jaynabonne
The command part can be anything you'd type at a command prompt, and you match it the same way. So if your command pattern is

combat #text#

then you can have commands like "combat attack", "combat flee", etc, and you'd just check the "text" parameter the way you do for any other Quest command. (I hope that's clear enough.)

switch (text) {
case ("attack") {
// do attack stuff
}
case ("flee") {
// run away
}
// etc.
}

Silver
jaynabonne wrote:You can either create a separate command for each or pass parameters to a single command or some combination of the two. The "command_name" part is actually a full command. It can be something like "fight" or "Combat_Attack" (both single commands) or something more complex like "Combat attack", where the command has pattern "Combat #text#" and you then have to check the text param to see what subcommand you're executing. Like:

You can:
{command:combat fight:Attack}
{command:combat magic:Use magic}
{command:combat item:Use item}
{command:combat escape:Escape}

This shows:

You can:
Attack
Use magic
Use item
Escape

and if you click "Attack" it sends the command "combat fight". The "combat" command can then compare text to "fight" to handle that particular area. One way or another you need to have unique commands for each case.

You can also do something like this:

  <command name="Dungeons_DoScriptCmd">
<pattern>DoScript #text1# #text2#;DoScript #text1#</pattern>
<script>
<![CDATA[
// text = object:attribute parameters
// text2 = parameter string (param1,param2,...)
source = Split(text1, ".")
object = StringListItem(source, 0)
attribute = StringListItem(source, 1)
if (not IsDefined("text2")) {
text2 = ""
}
args = Split(text2, ",")
params = NewDictionary()
argnum = 1
foreach (arg, args) {
dictionary add(params, "arg"+argnum, arg)
argnum = argnum + 1
}
//msg("object = " + object + ", attribute = " + attribute + ", params = " + params)
do (GetObject(object), attribute, params)
]]>
</script>

This command takes command text like "DoScript player.attack", where it will then invoke the script "attack" on the player object, or even something like "DoScript shop.buy axe", where you have an object named "shop" with a script named "buy". It will be called with a parameter named "arg1" set to "axe". Basically, the command line can be as complicated as you wish to parse.

A command with the latter script would be like: {command:DoScript combat.attack:Attack}, which would invoke the "attack" script on the "combat" object.


My head is slightly ajar. It does things I don't yet understand. Which is brilliant.

jaynabonne
When I said "you can do something like this" for that last bit of script, what I should have said was, "You can *use* this." You don't actually have to understand how it works as much as drop it in your game and then format the commands appropriately. I went that route in a game I was working on that had combat, items usage, purchases in shops, etc, and I got tired of creating commands for everything (besides the patterns, you have to have unique names, etc). So I made a single command that would invoke scripts on objects instead. Seemed to work nicely enough!

Silver
The game I'm working on doesn't do any of this stuff. But I need to know it in case I do need to know it iyswim. I hate missing out on info: the real nuggarts come round as often as Halley's Commet on here. And usually on threads about other things.

Silver
I only found out about Quest disregarding some file extensions and about how to circumvent that in Quest 5.6 by obsessively reading historical discussions.

HegemonKhan
okay... so the Command's pattern, will be matched by quest with the 3rd entry~option in the inline bracket:

{entry~option1:entry~option2:entry~option3}
{command:command_name:command_label~'alias concept'_as_seen_in_the_msg_script}

correct?

(ignore the bad grammer, as I just want to keep this simple as I can, lol)

msg ("You encountered an orc, do you " + {command:fight_command:combat attack orc} + ", " + {command:fight_command:combat magic orc} + ", " +  {command:fight_command:combat item orc} + ", " + {command:fight_command:combat magic player + ", " + {command:fight_command:combat item player + ", or " + {command:fight_command:combat escape player} + "?")

<command name="fight_command">
<pattern>combat #text# #object#</pattern>
<script>
switch (text) {
case ("attack") {
msg ("You attack the " + object.alias + ".")
}
case ("magic") {
if (object.name = "orc") {
msg ("You cast a fireball at the " + object.name + ".")
} else if (object.name = "player") {
msg ("You cast a healing spell upon yourself")
}
}
// etc etc etc
}
</script>
</command>

Silver
Maybe I'm getting lost here since you and jay have taken this to another level, but the whole point of the {command:whatever:whatever} is you dont need " + whatever.whatever + "

The text processor circumvents that type of coding for simplicity in strings.

jaynabonne
The text would be something like:

msg ("You encountered an orc, do you {command:combat attack orc:fight}, {command:combat magic orc:use magic}, {command:combat item orc:use an item}, or {command:combat escape player:run away}?")

The name of a command is not used (e.g. fight_command). Just the actual words as if you typed them yourself at a command prompt (and you can do that to test your commands!). To recap, what Silver said, the first part is "command" to signal it's a command, the second part is the command text if clicked (e.g. "combat attack orc"), and the third part is what is shown to the player. So in the above, the player would see:

You encountered an orc, do you fight, use magic, use an item, or run away?

And as Silver said, the markup is actually in the text. That is the whole point - not having to write script!

HegemonKhan
oh... okay... so I got messed up about the 2nd and 3rd entries (I understand them now) and messed up the msg syntax... still need to learn it better, lol (I got it now though).

Thank you, both of you, Silver and Jay, !!!

And sorry Silver for taking this a bit more into more advanced areas (Parameters usage) with Jay. You'll surely soon be able though to understand, you're learning fast, hehe.

(And Jay's omni-combat command ~ parsing, went right over both of our heads, hehe. I hope I'll get to understanding it... though I'm slow, you'll probably understand it before I do, heh)

Unexpected128
HegemonKhan wrote:You'll at some point get around to learning to code (hopefully), as it seems you already are moving towards it (switching between code view mode and the GUI~Editor mode, to see how the code converts into how it is done~looks in the GUI~Editor), hehe.

Silver was totally against coding... now he~she loves it, probably not going back much to the GUI~Editor anymore, just like me (as I too came into quest not knowing anything at all about coding, and but used quest to learn to code, to get where I'm at today: still a noob at coding, but I've come a long way, and Silver is making good code progress now too. If you want to learn to code, quest is really awesome for it). Code is indeed very scary at first, but as you slowly start to learn it, it's really not that difficult (it's really just a lot of algebra: algebraic substitutions, but coming up with creative~advanced code designs, that's hard, lol. But just the coding itself, isn't really as bad as it certainly does seem for people new to code). The GUI~Editor is great, but once you can code, you don't have much more need for it anymore.


Oh, I appreciate all the enthusiasm and encouragement, and I can see how coding would be very useful for bigger projects, but the game I'm making is fairly simple. It's just something fun I wanted to do to share with a group of friends, so as long as I can get all the basic stuff working properly, I'm happy with it :) Besides, I've always been terrible at math, so, personally, coding just isn't the way for me, hahah x3 It's not how my mind works at all.

HegemonKhan wrote:

try leaving the bracket choice as [EXPRESSION], and then in the text box, type in: result, see below

if -> [EXPRESSION] -> result

and see what happens ;)
(it's the exact same thing)

how is it in the GUI~Editor (too lazy to fire up quest to find out myself, lol) ???, something like this:

if -> [VARIABLE~whatever the label choice here] -> [RESULT]

or

if -> [RESULT]

???

Setting an "if" to "expression" and then "result" is what I tried after checking how the code converted to the GUI, yes! That's what it looks like, and it's working perfectly :D

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

Support

Forums