One thing you should know about ArmA engine is that it likes to create work for itself. And unless you tell it explicitly to take a break it will just keep on going and going. I’m talking about evaluating expressions resulting in either true or false in particular. Let’s look at this basic example:

if (a && b && c) then { //do something };

So if a and b and c are all true, the whole expression in () should evaluate to true and we have our code in {} executed. Basically EVERY variable above should be true so that whole expression evaluates to true. The expression is checked from left to right by the engine so ideally if a is false we shouldn’t need to check the rest of the expression. Well ArmA engine thinks different and will continue checking everything until it hits closing bracket ).

What does this mean in terms of writing the code? This means you are better off making multiple if statements to speed up your scripts. The above could be therefore optimised as:

if (a) then { if (b) then { if (c) then { //do something }; }; };

In this case if a is false the engine will ignore the code in {} and just carry on to other tasks. Luckily for us BETA 93632 introduced lazy evaluation switch to ArmA engine.

[93632] New: Lazy evaluation variants of scripting functions and / or.

To switch it on you need to use different syntax. Normal expression evaluation expects this syntax:

  • boolean [and/or] boolean [and/or] boolean … [and/or] boolean

Compare this to lazy evaluation syntax:

  • boolean [and/or] code [and/or] code … [and/or] code

It starts with boolean followed by code. You can only use boolean once at the start. You have to make the code to evaluate to true or false, just like boolean. So to switch lazy evaluation on we need to re-write our example as:

if (a && {b} && {c}) then { //do something };

It is not too bad, would have been better if it started with code too for clarity, but this will do. It even works with switch, while and waitUntil.

private ["_result","_step","_c"]; _result = "is false"; a = { _step = "1"; true; }; b = { _step = "2"; false; }; _c = { _step = "3"; true; }; scopeName "main"; while {call a && b && _c} do { _result = "is true"; breakTo "main"; }; hintSilent format ["Expression %1, quit at step %2", _result, _step];

The above example will output: Expression is false, quit at step 2. So here it is, my lazy evaluation for ArmA tutorial.