Getting AND and OR to work in a script

I'm trying to get the OR and AND conditions to work in a script.
Why does the code below not work?

if (game.pov.parent = Games Room) OR (game.pov.parent = Room){
msg ("Passed")
}


the 'if' Script requires the entire conditional expression(s) to be within its parenthesis:

if (game.pov.parent = Games Room or game.pov.parent = Room){
  msg ("Passed")
}

you can do this too, but it's totally pointless extra operations for the parser reading your script (unless it's really confusing and you need the extra parenthesis to better see/tell what you're doing: that is, if people need to read/understand what the code is doing):

if ((game.pov.parent = Games Room) or (game.pov.parent = Room)) {
  msg ("Passed")
}

the way you have your syntax, it gets understood by the parser as this:

1. if (game.pov.parent = Games Room)

ERROR: incorrect syntax

2. or (game.pov.parent = Room) {
  msg ("Passed")
}

ERROR: incorrrect syntax

Oddly enough, the syntax in this piece of code is valid; the reason it fails is because of a bug in the Quest interpreter. But if that bug wasn't there, it probably wouldn't do what you want.

See, you can put an if statement on a single line to save space. So this would work:

if (game.pov.parent = Games Room or game.pov.parent = Room) msg ("Passed")

So Quest sees your code as equivalent to:

if (game.pov.parent = Games Room) {
  OR (game.pov.parent = Room) {
    msg ("Passed")
  }
}

So… if the player is in the Games Room, it calls the function OR with two parameters; the first is the result of the expression game.pov.parent = Room (which is always false, because this code is only called in the Games Room), and the second is the script variable msg ("Passed").

There is no syntax error here; except that Quest's parser has a known bug which occasionally causes problems if you put the = operator in a function parameter.

HK already suggested how to fix your code; I would go for ((game.pov.parent = Games Room) or (game.pov.parent = Room)) simply because I use other programming languages where or binds tighter than =; but in practical terms it makes no difference.

I'd also add that or is a logical operator; OR isn't. That's why, if it wasn't for the parser error I mentioned, Quest would be complaining that it can't find a function named OR.


Thanks hegemonkhan and mrangel.

I was wondering if Quest was case sensitive for some things.

Hopefully the bug you wrote about will be fixed in the next Quest update.
Out of interest how often does Quest get updated? I suspect it will be a while before the next update as it was recently updated.


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

Support

Forums