Using "and" in IF scripts?

CheeseMyBaby
24 Apr 2018, 17:24I've been searching and searching the forums. I could've sworn I've seen someone exemplify this somewhere but I just can't find it. I'm starting to believe I've dreamed it.
Here's what I want to do in pseudocode:
IF x1
THEN Blah1
ELSE IF x2
THEN Blah2
ELSE IF x1 AND x2
THEN Blah3
Did I actually dream this is possible?
Like I said; I can't find anything about it and when I try to make it work in codeview I... well... can't.
mrangel
24 Apr 2018, 17:39If you do that, Quest looks at the first if statement. Is x1
true? Yes, it is. So do Blah1, and ignore the rest of the 'else' clauses.
If you want it to work, you need to do either make the first test explicit:
IF x1 and not x2
THEN Blah1
ELSE IF x2 and not x1
THEN Blah2
ELSE IF x1 AND x2
THEN Blah3
OR put the most specific case first
IF x1 AND x2
THEN Blah3
ELSE IF x1
THEN Blah1
ELSE IF x2
THEN Blah2

CheeseMyBaby
24 Apr 2018, 18:33Thanks MrAngel! Now I know it's possible.
One thing:
What would the actual code look like? Been trying and trying but it just won't come out right :(

CheeseMyBaby
24 Apr 2018, 18:57I get this
Error running script: Error compiling expression 'cane.here and GetBoolean(knob, "polished")': AndOrElement: Operation 'And' is not defined for types 'Object' and 'Boolean'
From this
if (cane.here and GetBoolean(knob, "polished"))
Been trying to move stuff around but the result is always the same... an error message.
mrangel
24 Apr 2018, 19:24"and" requires two booleans (true/false values).
From the error message, it looks like cane.here
is an object rather than a boolean.
In error messages like than, "Object" most often means the special object null
. As in, the attribute cane.here
hasn't been set yet. That's precisely the problem that GetBoolean was made for.
In that case, it would be safer to use:
if (GetBoolean(cane, "here") and GetBoolean(knob, "polished")) {

CheeseMyBaby
24 Apr 2018, 19:49Thanks a bunch mrangel, it's sorted now! (and I learned stuff too) :)