Syntax question that's really bugging me

Kazekai
Dunno where else to put this and since nobody else on the first topic page seemed to have to ask, I assume it's either a really stupid question or it was answered somewhere really obvious that I just haven't found yet but here we go anyway.

I'm doing the tutorial on the doc page, I'm hoping that I can make a text adventure for the sake of building myself up more to programming because I've tried it in the past and failed miserably either because I was too ashamed to ask a question or because I'm terrible at math and numbers so, hopefully I can remedy the first problem now and work at the second as I go.

Anyway, here's what's driving me nuts right now; my test game works fine, but a syntax string under the custom commands section of the tutorial page tells me to input this string as an expression: "You say \"" + text + "\", but nobody replies."

The thing is, even though it explains what the backslashes are, and I kind of understand what they are for, I really don't know why they need to be in that order. The message prints fine in-game but I just don't understand why there are two quotations behind the first backslash or why the message cannot be printed like this: "You say "\" + text + "\", but nobody replies." because that would make more sense, the "you say" would be completely surrounded by quotes and I wouldn't be stuck wondering why one quote is lost in oblivion when the command executes in-game.

It just looks lopsided to me in the proper way the game reads it, and I guess I was thinking that it looks that way to me because I am lacking understanding. The reason I'm asking about this is because I've had these dumb questions in the past when I try to learn things alone this course and they've hindered my ability to remember them so I'm hoping that if someone could take some time to explain this to me, I might be able to remember how to type this and understand the syntax better for future reference.

Also, I know there is an alternate way to type this string but since I am trying to use this as a learning tool, I didn't want to settle for half-knowledge in case some other program I might use in the future requires me to understand this kind of syntax, and like I said, I've run into a lot of confusion with syntax on other software and I'd like to remedy it in as universal a way as I can.

Alex
If you want an actual quote character to appear within a string, you put a backslash before it.

Otherwise, your quote character ends that bit of the string.

Below, I've put in large and bold the bit where you're saying "this is a quote character, not the end of the string":

"You say \"" + text + "\", but nobody replies."

You can think of it like this:

"You say QUOTE" + text + "QUOTE, but nobody replies."

Kazekai
Alex wrote:If you want an actual quote character to appear within a string, you put a backslash before it.

Otherwise, your quote character ends that bit of the string.

Below, I've put in large and bold the bit where you're saying "this is a quote character, not the end of the string":

"You say \"" + text + "\", but nobody replies."

You can think of it like this:

"You say QUOTE" + text + "QUOTE, but nobody replies."


Oh, so both \ and " are part of that command, and it's not just \, that makes so much more sense. Thanks.

HegemonKhan
I've been using quest to learn basic coding~programming from knowing nothing at all, so I know your situation well, and can hopefully be of help to you.

if you want to see my own beginning progress of learning, search for this thread (or just click the link to it, lol):

HK's Noobie Help Me thread ( viewtopic.php?f=10&t=3348&hilit=HK%27s+Noob+Help+Me+thread )

I was so overwhelmed just by the terms, trying to make sense of what was what, but looking back now, man was I stupid, laughs.

---------

understanding~getting the dynamic string expressions to work is one of the hardest things in the tutorial (or the "character creation" scripting), so don't feel bad at all, it's not easy to get it quickly.

here's a trick that I use:

break it up into 'chunks' and understand those chunks.

we're going to work backwards to understand this, so, say we've got this dynamic string expression:

output: HK is a 18 year old male human warrior.
(I wish I was 18, lol)

Scripting:

msg (player.alias + " is a " + player.age_integer + " year old " + player.gender_string + " " + player.race + " " + player.class + ".")

Tag Block: initial attribute creation settings:

<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
<alias>HK</alias>
<attr name="age_integer" type="int">18</attr>
<attr name="gender_string" type="string">male</attr>
<attr name="race" type="string">human</attr>
<attr name="class" type="string">warrior</attr>
</object>


a quick explanation of 'static' vs 'dynamic' strings:

static string = direct text = msg ("Hi, my name is HK.") ~OR~ msg ("Hi, my name is Kazekai.")

VS

dynamic string = algebraic substitution = use of variables~attributes:

msg ("Hi, my name is " + player.alias + ".")
if (player.alias = "HK"), then output: Hi, my name is HK.
if (player.alias = "Kazekai"), then output: Hi, my name is Kazekai.
see how we got a dynamic string expression by using the variable~attribute of 'player.alias', which returns an output differently depending on what we set it's value as being ("HK" vs "Kazekai").

also, this is important too:

a string~text, such as "HK", the quote characters~symbols as~within the code scripting itself, tell quest engine that this is a Type:String, and not a Type:Object, or nor a Type:int, or nor a Type:boolean.

player.toy_label = "ball" <---> String (text) Attribute Type; a String
player.toy = ball <---> Object Attribute Type; an Object
player.answers = "1" <---> String (text) Attribute Type; a String
player.eye_quantity = 2 <---> Integer (int) Attribute Type; an amount~quantity
player.answers = "true~false" <---> String (text) Attribute Type; a String
orc.dead = true~false <---> Boolean (Flag) Attribute Type; a Boolean~Flag

the 'NAME' Attribute is the unique 'ID' attribute for the quest engine, so you can't have two things with the same NAME attribute:

<attr name="strength" type="string">strong</attr>
<attr name="strength" type="int">100</attr>
ERROR !!!!!!

<object name="orc"></object>
<object name="orc"></object>
ERROR !!!!!

etc elements too (functions, verbs, commands, turnscripts, exits, timers, ect etc etc)

but, quest doesn't care about the 'ALIAS' Attribute:

<object name="monster_1">
<alias>orc</alias>
</object>
<object name="monster_2">
<alias>orc</alias>
</object>
NO error !

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

anyways, back to the most important thing in writing dynamic string expressions:

the 2 chunks:

1. " text (which includes a SPACE, the space bar key, character~symbol too) "
2. + Object.Attribute +

so, for our example:

msg (player.alias + " is a " + player.age_integer + " year old " + player.gender_string + " " + player.race + " " + player.class + ".")

the chunks:

player.alias +
" is a "
+ player.age_integer +
" year old "
+ player.gender_string +
" (SPACE) "
+ player.race +
" (SPACE) "
+ player.class +
"."

the secret to writing quest's dynamic string expressions, hehe.

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

as Alex already explained, the commands for output'ing double~single quotes in your msg scripts:

double quotes: /"
single quotes: '

Now, I just need to remember now that the slash is to the left of the double quote symbol, lol. I always got confused... haha.
(Or, I just keep using the single quotes... much easier~simplier, lol)

so...

since quest already uses the double quotes for defining a string~text portion~bit within your scripting, Alex has to use something else, the backslash+doublequote, so it acts more like a command-switch for inputing characters, like how is done with your file names with spaces:

%20 (I think ~ going off of old memory ~ I haven't seen it used in awhile) = (SPACE)

HK Game File.ext

becomes

HK%20Game%20File.ext

or for the computer's terminal~command line~prompt:

$p -> prompt
$g -> ^

$p$g -> (to get back your prompt functionality in a computer's terminal ~ command line~prompt)

(or whatever the letter for the up carrot symbol, meh)

Kazekai
That's a lot of info. Unfortunately I didn't understand all of it, I got lost on the differences between strings and other things but that's probably just because I haven't used those functions yet. (I'm dumb with theory.) Will keep the page open for reference though, I imagine I'll need to use those dynamic strings eventually and then I'm sure your info will click in my mind.

HegemonKhan
ya, I got a bit carried away, talking about more technical stuff where people get a bit confused with (getting the infamous non-matching Attribute Type errors), but that's too much info for you right now, as it just confused you.

though, this in the tutorial, IS a dynamic string expression:

msg ("You say \"" + text + "\")

the ' + text + ' is a dynamic variable being used in this 'msg' script

so, this is why I was trying to explain dynamic string expressions, and the secret to syntax-correctly writing in the 'msg' script

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

character creation (this is a good next learning step after completing the tutorial):

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

learning to write dynamic string expressions

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

the most important thing in writing dynamic string expressions:

the 2 chunks:

1. " text (which includes a SPACE, the space bar key, character~symbol too) "
2. + Object.Attribute +

so, for our example:

msg (player.alias + " is a " + player.age_integer + " year old " + player.gender_string + " " + player.race + " " + player.class + ".")

the chunks:

player.alias +
" is a "
+ player.age_integer +
" year old "
+ player.gender_string +
" (SPACE) "
+ player.race +
" (SPACE) "
+ player.class +
"."

the secret to writing quest's dynamic string expressions, hehe.

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

let me try again to just explain between static and dynamic string expressions (sorry I didn't do a good enough job of explaining this in my first post):

Static String Expression:

msg ("Hi, my name is HK.")

the output, when this program (well in this case, this 'msg' script) is run~executed, will always be (aka static) this: Hi, my name is HK.

Dynamic String Expression:

but, let's say we want the person playing the game, to be able to name his~her character...

msg ("What is your name?")
get input {
// the built-in 'get input' Function sets: result = whatever the person playing the game inputs (types in) to it.
player.alias = result
msg ("Hi, my name is " + player.alias + ".")
}


outputs:

What is your name?
// as the person playing the game, I would type in: HK
Hi, my name is HK.

What is your name?
// as the person playing the game, you would type in: Kazekai
Hi, my name is Kazekai.

this is dynamic, as the use of the variable-attribute (player.alias) is not permanently stuck as "HK", like how it is in my static string example of: msg ("Hi, my name is HK.")

this is algebraic substitution (conceptually, only):

X = 10
Y = X + 5
Y = 10 + 5
Y = 15

but, we're concatinating (literally putting~sticking together, we're NOT adding value amounts to make a new value amount) 'String:text' + 'variable:player.alias', so it would actually be this if we use the algebraic substitution example above:

X = 10
Y = X + "5"
Y = 10 + "5"
Y = 105

X = 10
Y = X + "" + X + "" + X + "5"
Y = 10 + "" + 10 + "" + 10 + "5"
Y = 1010105

X = cat
Y = X + "dog"
Y = catdog

X = cat
Y = X + " dog"
Y = cat dog

Y = (whatever you input here for Y)
msg ("Hi, my name is Y.")
outputs: Hi, my name is (whatever you inputed here for Y).

just replace the use of 'Y' with (for example) 'player.alias', and then the correct syntax too of:

msg ("Hi, my name is " + Y + ".")
msg (Hi, my name is " + player.alias + ".")

Kazekai
I'm still working through the initial tutorial and mostly figuring out these things on my own but when I came to the Ask/Tell section, I couldn't find the tab that was mentioned. I looked under features where the use/give checkbox was before but it isn't under there either. What am I supposed to do?

HegemonKhan wrote:ya, I got a bit carried away, talking about more technical stuff where people get a bit confused with (getting the infamous non-matching Attribute Type errors), but that's too much info for you right now, as it just confused you.

though, this in the tutorial, IS a dynamic string expression:

msg ("You say \"" + text + "\")

the ' + text + ' is a dynamic variable being used in this 'msg' script

so, this is why I was trying to explain dynamic string expressions, and the secret to syntax-correctly writing in the 'msg' script

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

character creation (this is a good next learning step after completing the tutorial):

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

learning to write dynamic string expressions

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

the most important thing in writing dynamic string expressions:

the 2 chunks:

1. " text (which includes a SPACE, the space bar key, character~symbol too) "
2. + Object.Attribute +

so, for our example:

msg (player.alias + " is a " + player.age_integer + " year old " + player.gender_string + " " + player.race + " " + player.class + ".")

the chunks:

player.alias +
" is a "
+ player.age_integer +
" year old "
+ player.gender_string +
" (SPACE) "
+ player.race +
" (SPACE) "
+ player.class +
"."

the secret to writing quest's dynamic string expressions, hehe.

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

let me try again to just explain between static and dynamic string expressions (sorry I didn't do a good enough job of explaining this in my first post):

Static String Expression:

msg ("Hi, my name is HK.")

the output, when this program (well in this case, this 'msg' script) is run~executed, will always be (aka static) this: Hi, my name is HK.

Dynamic String Expression:

but, let's say we want the person playing the game, to be able to name his~her character...

msg ("What is your name?")
get input {
// the built-in 'get input' Function sets: result = whatever the person playing the game inputs (types in) to it.
player.alias = result
msg ("Hi, my name is " + player.alias + ".")
}


outputs:

What is your name?
// as the person playing the game, I would type in: HK
Hi, my name is HK.

What is your name?
// as the person playing the game, you would type in: Kazekai
Hi, my name is Kazekai.

this is dynamic, as the use of the variable-attribute (player.alias) is not permanently stuck as "HK", like how it is in my static string example of: msg ("Hi, my name is HK.")

this is algebraic substitution (conceptually, only):

X = 10
Y = X + 5
Y = 10 + 5
Y = 15

but, we're concatinating (literally putting~sticking together, we're NOT adding value amounts to make a new value amount) 'String:text' + 'variable:player.alias', so it would actually be this if we use the algebraic substitution example above:

X = 10
Y = X + "5"
Y = 10 + "5"
Y = 105

X = 10
Y = X + "" + X + "" + X + "5"
Y = 10 + "" + 10 + "" + 10 + "5"
Y = 1010105

X = cat
Y = X + "dog"
Y = catdog

X = cat
Y = X + " dog"
Y = cat dog

Y = (whatever you input here for Y)
msg ("Hi, my name is Y.")
outputs: Hi, my name is (whatever you inputed here for Y).

just replace the use of 'Y' with (for example) 'player.alias', and then the correct syntax too of:

msg ("Hi, my name is " + Y + ".")
msg (Hi, my name is " + player.alias + ".")


I have to be honest, algebra has always confused me, so the example with words was really helpful because I was getting lost trying to figure out the numbers. I get what you mean now.

HegemonKhan
you have to find the tab (probably one of the 'game' Object's tabs), that has the option toggle check box for whether the tab you want is shown in the GUI~Editor, first before you can then click on that tab, obviously:

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

hope this helps.

Kazekai
HegemonKhan wrote:you have to find the tab (probably one of the 'game' Object's tabs), that has the option toggle check box for whether the tab you want is shown in the GUI~Editor, first before you can then click on that tab, obviously:

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

hope this helps.


Oh, that makes sense... The tutorial never specified I do that, at least I don't think it did. Either way, thank you for answering.

HegemonKhan
the tutorial is old, and I don't think it's updated often, and the need to hide~toggle the now numerous tabs happened with v540 to v550, aka happened recently.

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

Support

Forums