count: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (There is already a separate command for count array)
mNo edit summary
Line 30: Line 30:
____________________________________________________________________________________________
____________________________________________________________________________________________
   
   
|x1= <pre>_array = [soldier1, soldier2, soldier3]
|x1= <pre>_array = [1,2,2,3,4,4,4,5,6]
count _array</pre>
 
returns 3
 
The second usage of count counts how often a condition applies in an array.
 
<pre>_array = [1,2,2,3,4,4,4,5,6]
{_x==2} count _array</pre>
{_x==2} count _array</pre>



Revision as of 14:52, 19 January 2007

Hover & click on the images for description

Description

Description:
Counts elements in array for which given condition is true. It is calculated as follows: Set count to 0. For each element of array assign element as _x and evaluate condition expression. If true increase count.
Groups:
Uncategorised

Syntax

Syntax:
condition count array
Parameters:
condition: Code
array: Array
Return Value:
Integer

Examples

Example 1:
_array = [1,2,2,3,4,4,4,5,6]
{_x==2} count _array
returns 2

Additional Information

See also:
forEach

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note

Notes

Posted on August 3, 2006 - 14:27
hardrock
Notes from before the conversion: Use this to calculate how many "M16" mags a soldier has left. {_x == "M16"} count magazines soldier1 Take care when using count to determine how many units are left alive in a group: count units group player or count units groupname Will return the number of units the leader of the group thinks are alive. If some units have been killed out of sight of other members of the group then it may take sometime for this to be the actual numbers in the group. To determine exactly how many units are really alive in a group use: {alive _x} count units group player or {alive _x} count units groupname

Bottom Section