Using AND

Forgewright
12 Apr 2020, 16:09Can I use more than one and
in a line of code? If so does it change how it is written? I am getting an error and wondering if having three or more variables is wrong.
if (player.twohanded = null and player.shield = null and player.onehanded <> null) {
blah script
}
Also, is the <>
the wrong thing to do? Should I use not
somehow?
hegemonkhan
12 Apr 2020, 16:44you can have as many (as well as any combinations of) logic operatives ('and' or 'or' or 'not' or '<>' or '>' or '<' or '<=' or '>=' or '=') as you want
I'm guessing the error is from using the '<>' (not equal) comparison operation/symbol, as if using/doing it via coding, you need to use the 'CDATA' tags to tell quest that the '<' and '>' symbols are NOT to be seen as tags but as expression (comparison) operations/symbols:
(usually for people new to coding, the error issue is often them not having/using full/proper condition comparison expressions, but this isn't the case for you)
// within your scripting ELEMENT (Verb, Command, Turnscript, Timer, Object's Script Attribute, etc):
<!CDATA[
// all scripting (even if it doesn't use the '<' and/or '>' symbols) must go within this 'CDATA' tag, if you got any scripting that does use the '<' or '>'
// example:
// msg ("blah")
// even though this 'msg' Script doesn't have any '<' or '>' symbols, it still must go within the CDATA tag, as you do have scripting that uses the '<' or '>' symbols, seen below
if (player.twohanded = null and player.shield = null and player.onehanded <> null) {
blah script
}
]]>
quest has two operations/symbols for doing 'not equals':
if (VARIABLE_1 <> VARIABLE_2) { SCRIPTING }
// or, alternatively:
if (not VARIABLE_1 = VARIABLE_2) { SCRIPTING }
// or
if (VARIABLE_1 = not VARIABLE_2) { SCRIPTING }
// however, as explained above, if using the '<>', and doing the coding, you'll need the 'CDATA' tags, as just like with doing: 'greater than' (>), 'lesser than' (<), 'greater than or equal to' (>=), or 'lesser than or equal to' (<=), you need the 'CDATA' tags to tell quest that the '<' and '>' are to be understood as comparison operations/symbols, and not as tags:
parsing of comparison operations/symbols:
if (VARIABLE > VARIABLE) { SCRIPTING }
if (VARIABLE < VARIABLE) { SCRIPTING }
if (VARIABLE >= VARIABLE) { SCRIPTING }
if (VARIABLE <= VARIABLE) { SCRIPTING }
if (VARIABLE <> VARIABLE) { SCRIPTING }
VS, parsing of:
Tags:
<object name="room">
<inherit name="editor_room" />
<attr name="alias" type="string">dungeon99</attr>
</object>
// ---------------------------
// example in code of "everything (multiple use of 'ands', tags, comparison operations, and using the 'cdata' tag):
<object name="room">
<inherit name="editor_room" />
<attr name="alias" type="string">dungeon99</attr>
<attr name="example_script" type="script">
<![CDATA[
// NO error as you properly used/have the 'CDATA' tag
// the CDATA tag tells the quest parser to read any '<' and/or '>' symbols within it as comparison operations
if (10 <> 0 and 10 > 7 and 2 < 4) {
msg ("TRUE")
} else {
msg ("FALSE")
}
]]>
</attr>
</object>
// -------------------
// VS
// ----------------
<object name="room">
<inherit name="editor_room" />
<attr name="alias" type="string">dungeon99</attr>
<attr name="example_script" type="script">
// ERROR!!!, as you don't have the 'CDATA' tag
// due to not having the scripting below encased within the 'CDATA' tag, quest is reading the '<' and/or '>' symbols as tags, which causes an error as such code lines read as such tags are not proper syntax for tags, lol (the entire code is shifted/skewed/messed-up in terms of how its read, when the parser isn't reading comparison operation symbols as comparison operation symbols)
if (10 <> 0 and 10 > 7 and 2 < 4) {
msg ("TRUE")
} else {
msg ("FALSE")
}
</attr>
</object>
for complex comparison operations, you need to use the parenthesis, as the order of operations matters (just like it does with math):
an example:
A = false
B = true
C = true
if ((A and B) or C)
// (false and true) or true
// (false) or true
// TRUE
VS
if (A and (B or C))
// false and (true or true)
// false and (true)
// FALSE
for example with math:
(10 x 2) - 3 = 17
VS
10 x (2 - 3) = -10

Forgewright
12 Apr 2020, 17:35@hegemonkhan,
The documentation page shows two variables being used with AND with no further explanations.
Thank you for the information. Clears up a lot of possible questions.
The line of code I posted above is for functions I am creating in the Quest program and when I look at the game in code view the<![CDATA[
is added automatically.
mrangel
12 Apr 2020, 19:14I am getting an error
What's the error?
In most cases, the error message tells you everything you need to diagnose the problem; even if it's not easy to parse.
The line as you posted looks like it should work, unless it's one of Quest's frustrating lexing issues. But that's hard to debug without knowing what the actual error message is.
mrangel
12 Apr 2020, 19:23I've tested it on one of my own games, and it seems to work exactly as expected. No error message, and the 'else' block is executed.
My best guess at this point would be that one of those attributes is set to something other than an object; but in that case the error message will have told you exactly what the problem is, so you'd know it was nothing to do with "and"
hegemonkhan
12 Apr 2020, 19:48truth tables / logic gates: boolean/symbolic algebra/logic
definition/identity ("duh", lol) boolean logic:
true = TRUE
false = FALSE
'not' (negation / complement) boolean logic
not true = FALSE
not false = TRUE
'and' (conjunction) boolean logic:
true and true = TRUE
true and false = FALSE
false and true = FALSE
false and false = FALSE
'or' (disjunction) boolean logic:
true or true = TRUE
true or false = TRUE
false or true = TRUE
false or false = FALSE
https://en.wikipedia.org/wiki/Truth_table
https://en.wikipedia.org/wiki/Boolean_algebra
https://www.electronics-tutorials.ws/boolean/bool_6.html (rules/axioms/identities of boolean algebra, might not be best resource/info, meh)
https://www.youtube.com/watch?v=EPJf4owqwdA (rules/axioms/identities of boolean algebra, likely better resource, along with the actual algebra solving/simplifying of boolean/symbolic expressions/logic-gates too)
https://study.com/academy/lesson/symbolic-logic-definition-examples.html
https://philosophy.lander.edu/logic/symbolic.html (I think there's small page buttons at the bottom, there's more pages to read)