From Bohemia Interactive Community
Jump to navigation Jump to search

The notes mention using {alive _x} count units to check how many are actually alive, but I don't think 'alive' updates any faster than the group, i.e. "alive unit" returns true until the leader discovers the unit is dead. So, a more accurate count can be obtained with

{damage _x < 1} count units

--nomdeplume 10:24, 4 January 2010 (CET)

Actually, 'units' is updated much slower than 'alive', but independently of that, the point of the examples isn't really to show an "optimal" piece of code, but rather to just demonstrate the syntax. A lot of the examples don't make any sense in a real-life application - they were just chosen because they were brief and got the point across. --Kronzky 16:17, 4 January 2010 (CET)

"exitWith" inside a "count" loop overwrites the count result

As I tested my favorite way of using count in a trigger condition, I got a little confused. So this is what I often do:

if({if(_x fulfills condition) exitWith {true}; false} count _array isEqualTo 1) then { //do whatever here }; (Example from count BIKI page, now corrected)

I just realized that this does not seem to work with isEqualTo 1 anymore as the count now returns true instead of 1 as it used to do.

So it seems, the statement instead has to be something like this: if({if(_x fulfills condition) exitWith {1}; false} count _array isEqualTo 1) then { //do whatever here };

But I'm wondering why that is as count supposedly counts only elements which have a true condition. But using an exitWith inside the condition seems to break through that habit and set the result of the count as the exitWith value.


Non-bool interior result

Here is another example to further clarify my note:

{ _x createVehicleLocal (getPos player); } count ["Rabbit","Goat","Sheep"]; This throws "Error Type Object, expected Bool" because createVehicleLocal returns an object. To avoid this a bool can be added at the end of the loop like so: { _x createVehicleLocal (getPos player); false } count ["Rabbit","Goat","Sheep"]; Alternatively forEach can be used instead of count. Note exitWith does not return anything inside the loop. If it executes then it exits the loop and the return is outside of the count.

Ebay (talk) 21:55, 22 August 2016 (CEST)