count – Talk
m (Reverted edits by Heecf..... (talk) to last revision by Kronzky) |
|||
Line 5: | Line 5: | ||
--[[User:Nomdeplume|nomdeplume]] 10:24, 4 January 2010 (CET) | --[[User:Nomdeplume|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. --[[User:Kronzky|Kronzky]] 16:17, 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. --[[User:Kronzky|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: | |||
<code>if({if('''_x fulfills condition''') exitWith {true}; false} '''count''' _array isEqualTo 1) then | |||
<nowiki>{ | |||
//do whatever here | |||
};</nowiki></code> | |||
(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: | |||
<code>if({if('''_x fulfills condition''') exitWith {'''1'''}; false} '''count''' _array isEqualTo 1) then | |||
<nowiki>{ | |||
//do whatever here | |||
};</nowiki></code> | |||
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. |
Revision as of 18:47, 29 December 2014
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.