Page 1 of 1

Events: Logical Operators

Posted: Tue Aug 03, 2010 11:37 pm
by AH4Ever
How do you use both logical operators within a condition section of an event?

Is it even possible?

Will a configuration such as this work:

<condition>
...<or>
......<expression>
......</expression>
......<expression>
......</expression>
...</or>
...<and>
......<expression>
......</expression>
...</and>
</condition>

RE: Events: Logical Operators

Posted: Wed Aug 04, 2010 5:07 am
by doomtrader
Yes, this should work.

RE: Events: Logical Operators

Posted: Wed Aug 04, 2010 2:43 pm
by Bleck
ORIGINAL: AH4Ever

Will a configuration such as this work:

<condition>
...<or>
......<expression>
......</expression>
......<expression>
......</expression>
...</or>
...<and>
......<expression>
......</expression>
...</and>
</condition>
This won't work as you think. Look:

Code: Select all

 <condition>
 ...<or>
 ......<expression1></expression1>
 ......<expression2></expression2>
 ...</or>
 ...<and>
 ......<expression3></expression3>
 ......<expression4></expression4>
 ...</and>
 </condition>
It can be translated to:

Code: Select all

if (expression1 OR expression2) (expression3 AND expression4) then...
As you can see there is nothing co connect both brackets (OR bracket and AND bracket). It should look like this:

Code: Select all

if ( (expression1 OR expression2) AND (expression3 AND expression4) ) then...
or this:

Code: Select all

if ( (expression1 OR expression2) OR (expression3 AND expression4) ) then...
In other words, there should be only one <and> or <or> node in <condition>, and in this <and> or <or> node you can mix them. For example:

Code: Select all

 <condition>
 ...<and>
 ......<or>
 .........<expression1></expression1>
 .........<expression2></expression2>
 ......</or>
 ......<and>
 .........<expression3></expression3>
 .........<expression4></expression4>
 ......</and>
 ...</and>
 </condition>
 
can be translated as "if any of (expr1 or expr2) and both (expr3 and expr4) then..."


Hope that helps.

RE: Events: Logical Operators

Posted: Wed Aug 04, 2010 2:45 pm
by Bleck
to delete

RE: Events: Logical Operators

Posted: Wed Aug 04, 2010 2:45 pm
by Bleck
to delete

RE: Events: Logical Operators

Posted: Thu Aug 05, 2010 1:12 am
by AH4Ever
Thank you, using your example produced what you see.
I hope you approve and it works.


<condition>
...<and>
......<and>
......<!--Random check-->
......<expression>
.........<leftOperand method="System.GetRandomNumber" param0="2" param1="150"/>
.........<operator value="greaterOrEqual"/>
.........<rightOperand constValue="61"/>
......</expression>
......<!--Flag not fired yet-->
......<expression>
.........<leftOperand method="Flag.GetValue" param0="5045"/>
.........<operator value="equals"/>
.........<rightOperand constValue="0"/>
......</expression>
......</and>
......<or>
......<!--Ships at sea-->
......<expression>
.........<leftOperand method="AI.IsSeaZonePatrolled" param0="2" param1="12" param2="0"/>
.........<operator value="equals"/>
.........<rightOperand constValue="1"/>
......</expression>
......<!--Ships at sea-->
......<expression>
.........<leftOperand method="Country.GetShipsAmountInSeaZone" param0="2" param1="12" param2="41"/>
.........<operator value="equals"/>
.........<rightOperand constValue="1"/>
.......</expression>
......</or>
...</and>
</condition>

RE: Events: Logical Operators

Posted: Thu Aug 05, 2010 2:29 am
by Bleck
Yes, this should work.