Page 1 of 1

multiple AND OR how does it work?

Posted: Sat Apr 11, 2015 11:45 am
by Bugala
to keep code bit clearer, i am trying to implement conditions in same line.

Heres what i have currently:

Code: Select all

if A = true or B=true
               if C=true
                     thenstuff
by other words, c must always be true, while only a or b needs to be true in addition to c.

but is it possible to do something like:

Code: Select all

if C = true AND A=true or B=true
and if it is possible to have them in same line, then how does the logic in this go, that should i put OR first, or AND first etc.

Re: multiple AND OR how does it work?

Posted: Sat Apr 11, 2015 2:33 pm
by jalih
Bugala wrote: Heres what i have currently:

Code: Select all

if A = true or B=true
               if C=true
                     thenstuff
by other words, c must always be true, while only a or b needs to be true in addition to c.

but is it possible to do something like:

Code: Select all

if C = true AND A=true or B=true
I think Hollywood uses the same operator precedence as Lua. In this case the AND operator is evaluated before the OR operator. It's probably best to always use explicit parentheses to make your intentions clear.

Your second code could simply be written as :

Code: Select all

If ( A OR B ) AND C
  DoStuff()
EndIf

Re: multiple AND OR how does it work?

Posted: Sat Apr 11, 2015 3:45 pm
by Bugala
Excellent!

Thanks a lot Jalih! I didnt know you could put those things inside (), that makes it quite clear how to do it.