Using the 'Or' binary operator in Quest expressions
Vega
19 Dec 2015, 04:42Hi
I am trying to use the binary operator 'or' in an expression but I am getting an error.
I'm new to coding and to Quest, and I think Quest is run on javascript, and I don't know how the java syntax works.
-----------------------------------------------------------------------------------------------
The expression I want to use is as follows:
IF ... PLAYER IS CARRYING OBJECT ... EXPRESSION(x or y or z)
THEN (abc)
--------------------------------------------------------------------------------------------------
I am also new to writing code in forums so please forgive my newbie mockup.
I hope the above explains what I am asking.
K-
ps. I have attached a screen shot of the error *AND* the code screen. On the screen I want to use OR in the expression twice...

I am trying to use the binary operator 'or' in an expression but I am getting an error.
I'm new to coding and to Quest, and I think Quest is run on javascript, and I don't know how the java syntax works.
-----------------------------------------------------------------------------------------------
The expression I want to use is as follows:
IF ... PLAYER IS CARRYING OBJECT ... EXPRESSION(x or y or z)
THEN (abc)
--------------------------------------------------------------------------------------------------
I am also new to writing code in forums so please forgive my newbie mockup.
I hope the above explains what I am asking.
K-
ps. I have attached a screen shot of the error *AND* the code screen. On the screen I want to use OR in the expression twice...


Vega
19 Dec 2015, 04:44Twistednets or nets2 or nets3 are all objects and I want to use the or binary operator in the expression, but I am receiving an error.

XanMag
19 Dec 2015, 05:06I could totally be making this up, but the Pixie helped me with 'and'... not sure if it would work for an 'or' or not, but it can't hurt to try it out, right?
If, expression obj = twistednets or obj = nets2 or obj = nets 3
Then... blah blah blah
So, put 'obj = ' in front of your 'nets'.
It probably will be laughable to experienced coders, but I used a similar bit of code for my 'and' needs. Try it out and see what happens? Good luck.
If, expression obj = twistednets or obj = nets2 or obj = nets 3
Then... blah blah blah
So, put 'obj = ' in front of your 'nets'.
It probably will be laughable to experienced coders, but I used a similar bit of code for my 'and' needs. Try it out and see what happens? Good luck.
HegemonKhan
19 Dec 2015, 07:22yes! someone who seems interested in coding, hehe
I enjoy trying to help with coding, being that I was a noob at coding 2-3 years ago, and am still a code noob learning to get better, hehe.
------------------
Quest uses its own language, but it's scripting code syntax is similar to C++ and~or Java, and it's main code is very similar to XML (a web~browser language like HTML ~ it's all the ' <xxx>xxx</xxx> ' or ' <xxx /> ' stuff that I like to call the 'physical creation' tag code lines~blocks), and its coding features is similar to Python (usage of Lists and Dictionaries for example), as Quest~Alex is European and Python is much more popular in Europe than in the U.S.)
I'd recommend downloading notepad++ ( https://notepad-plus-plus.org/ ), as it's a good free software, you can select the programming language you want (the menu bar at the top once you got it installed and open~running), such as 'XML' for quest coding, or whatever language, for whatever else, like maybe writing JS (JavaScript) code for whatever, hehe.
----------------
when using 'and' and 'or' logic operators, you need full statements for each of your conditions, here's how I like to show the general syntax of a statement:
Object_name.Attribute_name = Value_or_Expression
for examples:
3 condition statements, if:
player.strength = 100
player.endurance = 100
player.dexterity = 100
and how to write the syntax correctly (using only basic-simple examples):
if (player.strength = 100 and player.endurance = 100 and player.dexterity = 100) { // scripts }
if (player.strength = 100 or player.endurance = 100 or player.dexterity = 100) { // scripts }
(you can use as much parenthesis as you want, just like in math, for grouping ~ order of operations)
------------
and just if you don't understand the logic truth tables of 'and' and 'or', here they are:
https://en.wikipedia.org/wiki/Truth_table
AND:
true and true = TRUE
true and false = FALSE
false and true = FALSE
false and false = FALSE
OR:
true or true = TRUE
true or false = TRUE
false or true = TRUE
false or false = FALSE
NEGATIVE (NOT):
not true = FALSE
not false = TRUE
syntax in quest:
not Object_name.Attribute_name = Value_or_Expression
~OR~
Object_name.Attribute_name <> Value_or_Expression
DeMorgan's Laws:
not (a or b) == (not a) and (not b)
not (a and b) == (not a) or (not b)
-------------
P.S.
also, when posting code (and~or anything that requires you to preserve your indenting formating) and~or anything of length:
use the site's 'code' tag code line~block, via:
[code.]your mass of code or text wall lol[/code.]
but without the periods~dots in the brackets, which will produce this:
for an example of code formatting being preserved:
vs not being preserved:
<function name="character_creation_function">
msg ("What is your name?")
get input {
player.alias = result
show menu ("What is your sex?", split ("male;female", ";") {
player.sex = result
show menu ("What is your race?", split ("human;dwarf;elf", ";"), false) {
player.race = result
show menu ("What is your class?, split ("warrior;thief;cleric;wizard", ";") {
player.class = result
msg (player.alias + " is a " + player.sex + " " + player.race + " " + player.class + ".")
}
}
}
}
</function>
-------------------
p.s.s.
for your example of using the 'Got' Function with 'and' and~or 'or', this is the correct syntax (showing an 'if~else if~else' structural 'if' block, and I am addressing every combination of conditions possible lol, below for an example only):
(the code below shows how to do~write~code in the full Function Statements are needed for each condition)
(change my 'object_X1..3' to the names of your Objects, of course)
(I put in spacing, just to help you see the parenthesis and its format~syntax structure better)
unfortunately, the direct code writing is a bit different from writing code in for the GUI~Editor's Scripts, as can be seen (compare the above with the below), which causes lots of confusion to code noobs:
(I don't know the GUI~Editor's Script options very well, so I just use the ' [EXPRESSION] ' option, as this let's me write in the code for the scripting that I want to use, lol)
add new script -> scripts -> 'if' Script -> if [EXPRESSION] = Got (object_X1) and Got (object_X2) and Got (object_X3)
-> then -> add new script -> (whatever script you want)
else if [EXPRESSION] = Got (object_X1) and Got (object_X2)
-> then -> add new script -> (whatever script you want)
// and etc etc etc

------------------
Quest uses its own language, but it's scripting code syntax is similar to C++ and~or Java, and it's main code is very similar to XML (a web~browser language like HTML ~ it's all the ' <xxx>xxx</xxx> ' or ' <xxx /> ' stuff that I like to call the 'physical creation' tag code lines~blocks), and its coding features is similar to Python (usage of Lists and Dictionaries for example), as Quest~Alex is European and Python is much more popular in Europe than in the U.S.)
I'd recommend downloading notepad++ ( https://notepad-plus-plus.org/ ), as it's a good free software, you can select the programming language you want (the menu bar at the top once you got it installed and open~running), such as 'XML' for quest coding, or whatever language, for whatever else, like maybe writing JS (JavaScript) code for whatever, hehe.
----------------
when using 'and' and 'or' logic operators, you need full statements for each of your conditions, here's how I like to show the general syntax of a statement:
Object_name.Attribute_name = Value_or_Expression
for examples:
3 condition statements, if:
player.strength = 100
player.endurance = 100
player.dexterity = 100
and how to write the syntax correctly (using only basic-simple examples):
if (player.strength = 100 and player.endurance = 100 and player.dexterity = 100) { // scripts }
if (player.strength = 100 or player.endurance = 100 or player.dexterity = 100) { // scripts }
(you can use as much parenthesis as you want, just like in math, for grouping ~ order of operations)
------------
and just if you don't understand the logic truth tables of 'and' and 'or', here they are:
https://en.wikipedia.org/wiki/Truth_table
AND:
true and true = TRUE
true and false = FALSE
false and true = FALSE
false and false = FALSE
OR:
true or true = TRUE
true or false = TRUE
false or true = TRUE
false or false = FALSE
NEGATIVE (NOT):
not true = FALSE
not false = TRUE
syntax in quest:
not Object_name.Attribute_name = Value_or_Expression
~OR~
Object_name.Attribute_name <> Value_or_Expression
DeMorgan's Laws:
not (a or b) == (not a) and (not b)
not (a and b) == (not a) or (not b)
-------------
P.S.
also, when posting code (and~or anything that requires you to preserve your indenting formating) and~or anything of length:
use the site's 'code' tag code line~block, via:
[code.]your mass of code or text wall lol[/code.]
but without the periods~dots in the brackets, which will produce this:
your mass of code of text wall lol
for an example of code formatting being preserved:
<function name="character_creation_function">
msg ("What is your name?")
get input {
player.alias = result
show menu ("What is your sex?", split ("male;female", ";") {
player.sex = result
show menu ("What is your race?", split ("human;dwarf;elf", ";"), false) {
player.race = result
show menu ("What is your class?, split ("warrior;thief;cleric;wizard", ";") {
player.class = result
msg (player.alias + " is a " + player.sex + " " + player.race + " " + player.class + ".")
}
}
}
}
</function>
vs not being preserved:
<function name="character_creation_function">
msg ("What is your name?")
get input {
player.alias = result
show menu ("What is your sex?", split ("male;female", ";") {
player.sex = result
show menu ("What is your race?", split ("human;dwarf;elf", ";"), false) {
player.race = result
show menu ("What is your class?, split ("warrior;thief;cleric;wizard", ";") {
player.class = result
msg (player.alias + " is a " + player.sex + " " + player.race + " " + player.class + ".")
}
}
}
}
</function>
-------------------
p.s.s.
for your example of using the 'Got' Function with 'and' and~or 'or', this is the correct syntax (showing an 'if~else if~else' structural 'if' block, and I am addressing every combination of conditions possible lol, below for an example only):
(the code below shows how to do~write~code in the full Function Statements are needed for each condition)
(change my 'object_X1..3' to the names of your Objects, of course)
(I put in spacing, just to help you see the parenthesis and its format~syntax structure better)
if ( Got (object_X1) and Got (object_X2) and Got (object_X3) ) {
// scripts
} else if ( Got (object_X1) and Got (object_X2) ) {
// scripts
} else if ( Got (object_X1) and Got (object_X3) ) {
// scripts
} else if ( Got (object_X2) and Got (object_X3) ) {
// scripts
} else if ( Got (object_X1) ) {
// scripts
} else if ( Got (object_X2) ) {
// scripts
} else if ( Got (object_X3) ) {
// scripts
} else {
// scripts
}
unfortunately, the direct code writing is a bit different from writing code in for the GUI~Editor's Scripts, as can be seen (compare the above with the below), which causes lots of confusion to code noobs:
(I don't know the GUI~Editor's Script options very well, so I just use the ' [EXPRESSION] ' option, as this let's me write in the code for the scripting that I want to use, lol)
add new script -> scripts -> 'if' Script -> if [EXPRESSION] = Got (object_X1) and Got (object_X2) and Got (object_X3)
-> then -> add new script -> (whatever script you want)
else if [EXPRESSION] = Got (object_X1) and Got (object_X2)
-> then -> add new script -> (whatever script you want)
// and etc etc etc
HegemonKhan
19 Dec 2015, 08:30@ XanMag:
this that Pixie gave to you ~ helped you with:
If, expression obj = twistednets or obj = nets2 or obj = nets 3
is only for: Functions with Parameter usage and~or 'for~foreach' loop scriptings
as the 'obj' (or whatever you want to name~call~label it as, I like using 'object_x' instead of 'obj', lol) is merely a custom placeholder LOCAL Variable, and thus wouldn't work for Vega's code, as he~she is using the 'Got' Function, which requires an actual Object (aka: the name of the Object) for its Parameter input, as this is the Object that is checked for if it is in the player's inventory (the 'ScopeInventory()' Function that gets the built-in 'player' Player Object's internal Objectlist Attribute) or not.
this that Pixie gave to you ~ helped you with:
If, expression obj = twistednets or obj = nets2 or obj = nets 3
is only for: Functions with Parameter usage and~or 'for~foreach' loop scriptings
as the 'obj' (or whatever you want to name~call~label it as, I like using 'object_x' instead of 'obj', lol) is merely a custom placeholder LOCAL Variable, and thus wouldn't work for Vega's code, as he~she is using the 'Got' Function, which requires an actual Object (aka: the name of the Object) for its Parameter input, as this is the Object that is checked for if it is in the player's inventory (the 'ScopeInventory()' Function that gets the built-in 'player' Player Object's internal Objectlist Attribute) or not.
The Pixie
19 Dec 2015, 08:50XanMag wrote:I could totally be making this up, but the Pixie helped me with 'and'... not sure if it would work for an 'or' or not, but it can't hurt to try it out, right?
If, expression obj = twistednets or obj = nets2 or obj = nets 3
Then... blah blah blah
So, put 'obj = ' in front of your 'nets'.
It probably will be laughable to experienced coders, but I used a similar bit of code for my 'and' needs. Try it out and see what happens? Good luck.
That is pretty much the problem. Doing it in the GUI makes the solution a bit more tricky though. This is what it is at the moment:
if [player is carrying object] [expression] [Twistednets or nets2 or nets3]
Quest first tries to do the [Twistednets or nets2 or nets3] bit, but they are all objects, not Booleans (aka flags), and so the error. You need to change the [player is carrying object] option to [expression], and then paste in this:
Got(Twistednets) or Got(nets2) or Got(nets3)