multiple AND OR how does it work?

Find quick help here to get you started with Hollywood
Post Reply
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

multiple AND OR how does it work?

Post 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.
jalih
Posts: 276
Joined: Fri Jun 18, 2010 8:08 pm
Location: Finland

Re: multiple AND OR how does it work?

Post 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
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: multiple AND OR how does it work?

Post 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.
Post Reply