count: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
No edit summary
No edit summary
Line 35: Line 35:


In general:<br>
In general:<br>
{condition} '''count''' [[array]] <br>
{condition} '''count''' array <br>
returns the number of elements in the array for which the '''condition''' is true.  If {condition} is not specified then the number of elements in the array is returned.
returns the number of elements in the array for which the '''condition''' is true.  If {condition} is not specified then the number of elements in the array is returned.



Revision as of 23:19, 2 May 2006


condition count array


Operand types:

condition: String

array: Array

Type of returned value:

Number

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.


Example:

{_x > 2} count [0, 1, 1, 2, 3, 3] ...... Result is 2


In general:
{condition} count array
returns the number of elements in the array for which the condition is true. If {condition} is not specified then the number of elements in the array is returned.

Example:

count [0, 1, 1, 2, 3, 3] ...... Result is 6


Comments:

(1) Use this to calculate how many "M16" mags a soldier has left.

("_x == {M16}" count magazines soldier1)


(2) 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