[SOLVED] Double Checking Syntax :)

Anonynn
28 Sept 2016, 06:05I probably already know the answer to this, but I need to double check. If you have a boolean on the game object and you want to use it in a script, it would be...
{if game.blahblah=True:}
Right?
Thanks in advance!
hegemonkhan
28 Sept 2016, 06:30for text processor commands, you almost got it:
http://docs.textadventures.co.uk/quest/text_processor.html
{if game.NAME_OF_BOOLEAN_ATTRIBUTE:YOUR_DESIRED_TEXT_OUTPUT} // for '=true' --- quest understands/defaults that having no '= true/false', is '=true', so when you want to be checking for true, you don't need the '=true' on it (and it saves an un-needed checking operation, as it's programmed to already be understood/defaulted as '=true')
and for doing false, you can do it two ways:
{if game.NAME_OF_BOOLEAN_ATTRIBUTE=false:YOUR_DESIRED_TEXT_OUTPUT}
~OR~
{if not game.NAME_OF_BOOLEAN_ATTRIBUTE:YOUR_DESIRED_TEXT_OUTPUT}
but, again, in this case, using the 'not' syntax is more efficient (less operations done), than using the '=false' syntax
as for directly in code scripting:
if (game.NAME_OF_BOOLEAN_ATTRIBUTE) { // for 'true' --- same reasoning as explained above, the '=true' is not needed
// script(s)
}
// optionally (as many as you want):
else if (CONDITION_FULL_STATEMENT/S) {
// script(s)
}
// optionally:
else {
// script(s)
}
if (game.NAME_OF_BOOLEAN_ATTRIBUTE = false) { // for 'false' --- again, using the 'not' syntax is better
// script(s)
}
// optionally (as many as you want):
else if (CONDITION_FULL_STATEMENT/S) {
// script(s)
}
// optionally:
else {
// script(s)
}
// OR:
if (not game.NAME_OF_BOOLEAN_ATTRIBUTE) { // for 'false' --- same reasoning as explained above, the 'not' syntax is better than the '=false' syntax
// script(s)
}
// optionally (as many as you want):
else if (CONDITION_FULL_STATEMENT/S) {
// script(s)
}
// optionally:
else {
// script(s)
}
oh, and real quick explanation:
a full statement in quest coding (think of like what makes a full sentence in human language: subject and verb):
Attribute VARIABLES:
NAME_OF_OBJECT.NAME_OF_ATTRIBUTE
~OR~
NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = VALUE_OR_EXPRESSION
Variable VARIABLES:
NAME_OF_Variable
~OR~
NAME_OF_Variable = VALUE_OR_EXPRESSION
Conditional (Full) Statements:
(a full statement is required for each of your conditionals!)
Attribute VARIABLES:
(I'm leaving off the optional 'else ifs' and 'else' --- too much work)
if (NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = VALUE_OR_EXPRESSION) {
// script(s)
}
if (NAME_OF_OBJECT_1.NAME_OF_ATTRIBUTE_1 = VALUE_OR_EXPRESSION and NAME_OF_OBJECT_2.NAME_OF_ATTRIBUTE_2 = VALUE_OR_EXPRESSION and NAME_OF_OBJECT_3.NAME_OF_ATTRIBUTE_3 = VALUE_OR_EXPRESSION) {
// script(s)
}
if (NAME_OF_OBJECT_1.NAME_OF_ATTRIBUTE_1 = VALUE_OR_EXPRESSION or NAME_OF_OBJECT_2.NAME_OF_ATTRIBUTE_2 = VALUE_OR_EXPRESSION or NAME_OF_OBJECT_3.NAME_OF_ATTRIBUTE_3 = VALUE_OR_EXPRESSION) {
// script(s)
}
// and all the other infinite (if you had infinite conditionals, lol) combinations of 'and' and 'or' usages... you can use parenthesis to split it up as you want for desired ordering/order-of-operations, just like in/with math: if ((cond1 and cond2) or (cond3 and cond4)) { /* scripts */ } --- though this is boolean logic, which is a bit difficult to follow/understand at first...
Variable VARIBLES:
if (NAME_OF_Variable = VALUE_OR_EXPRESSION) {
// script(s)
}
if (NAME_OF_Variable_1 = VALUE_OR_EXPRESSION_1 and NAME_OF_Variable_2 = VALUE_OR_EXPRESSION_2 and NAME_OF_Variable_3 = VALUE_OR_EXPRESSION_3) {
// script(s)
}
if (NAME_OF_Variable_1 = VALUE_OR_EXPRESSION_1 or NAME_OF_Variable_2 = VALUE_OR_EXPRESSION_2 or NAME_OF_Variable_3 = VALUE_OR_EXPRESSION_3) {
// script(s)
}
// the syntax is similiar as shown/explained near the very top of this post for specifically Boolean Attributes/Variables VARIABLES (as it's only either: true or false)
essentially, the memorization/understanding/conception is that there's 3 main grammer/logic operators/opertions, and in quest, they are:
conjuntion: 'and'
disjunction: 'or'
negation (opposite): 'not' or '<>'
Truth Tables:
IDENTITY/DEFINITION (this is a bit obvious hopefully, but whatever, for completeness):
false -> FALSE // yes, 'false' is 'FALSE', lol
true -> TRUE // yes, 'true' is 'TRUE', lol
NEGATION/NOT (opposite):
not false -> TRUE
not true -> FALSE
AND:
true and true -> TRUE
false and true -> FALSE
true and false -> FALSE
false and false -> FALSE
OR:
true or true -> TRUE
false or true -> TRUE
true or false -> TRUE
false or false -> FALSE
if (HK.sex = "male") { then do blah
// if (true), true -> TRUE, so DO blah
if (HK.sex = "female") { then do blah
// if (false), false -> FALSE, so do NOT do blah
if (HK.sex = "male" and HK.sex = "female") { then do blah
// if (true and false), true and false -> FALSE, so do NOT do blah
if (HK.sex = "male" or HK.sex = "female") { then do blah
// if (true or false), true or false -> TRUE, so DO blah
if (HK.sex = "male" and HK.favorite_color = "black") { then do blah
// if (true and true), true and true -> TRUE, so DO blah
if (not HK.sex = "male") { then do blah
// if (not true), not true -> FALSE, so do NOT do blah
if (not HK.sex = "female") { then do blah
// if (not false), not false -> TRUE, so DO blah
if (not HK.sex = "male" and not HK.favorite_color = "black") { then do blah
// if ([(not true) and (not true)]), [(not true -> false) and (not true -> false)] -> [(false) and (false)] -> FALSE, so do NOT do blah
if (not HK.sex = "female" and not HK.favorite_color = "pink") { then do blah
// if ([(not false) and (not false)]), [(not false -> true) and (not false -> true)] -> [(true) and (true)] -> TRUE, so DO blah
I'm taking a symbolic logic philosophy class right now, and our professor gives a good explanation on how to understand boolean logic stuff:
pretend you got a 5 year old kid, and you promise him/her whatever (see the boolean logic conditionals), well, do you keep your promise or not? --- let's do an example:
AND:
Be quiet during the car ride, and I'll take you to both: disneyland and a pizza restuarant. For me to keep my promise (TRUE), I must take my kid to both disneyland (true) and a pizza restaurant (true). However, if I take my kid to neither place (false and false) or if I take my kid to only one place (false and true --- or --- true and false), then I broke my promise (FALSE).
OR:
Be quiet during the car ride, and I'll take you to either: disneyland or a pizza restuarant. For me to keep my promise (TRUE), I must take my kid to either: both disneyland (true) and a pizza restaurant (true), or to just one of the places (true and false --- or --- false and true). However, if I take my kid to neither place (false and false), then I broke my promise (FALSE). While my kid would of course like to go to both disneyland and a pizza restaurant, if I take him/her to one place or the other, I've kept my promise (TRUE). And, if I've taken him to both places (true and true), then I still kept my promise (TRUE), as my kid did go to one of them.
NOT:
this logic should be pretty straight forward... but the examples below, don't work so well/straight-forward, lol.... meh
be quiet and I'll (whisperingly) not (and now back to audibly) take you to disneyland
the kid heard me saying I'm taking him/her to disneyland (true), so if I don't (not true), then I'm breaking my promise (FALSE)
be quiet and I'll NOT take you to disneyland... not/just-kidding, we'll go to disneyland!
the kid heard me saying I'm NOT not-taking him/her to disneyland (NOT false == false ... NOT/just-kidding), so if I don't (NOT true == true... not/just-kidding... ya, I'm cruel... just for this example, lol), then I'm breaking my promise (FALSE)

Anonynn
28 Sept 2016, 17:09Okay! So I was doing it right. Thanks, HK. :D