Page tree
Skip to end of metadata
Go to start of metadata

Introduced in



Description:Returns a count for either:
  • The number of elements in an array .
  • The number of elements in an array, for which the given condition is true.
  • The number of sub-entries in a configuration object.


Syntax:condition count array
  • condition: Code - Condition that must return true to be counted. The variable _x contains the currently tested element (optional).
  • array: Array - The array.
Return Value:Number

Alternative Syntax

Syntax:count configname
  • configname: Config-2 - Configuration object.
Return Value:Number


_cnt = count [0, 0, 1, 2]; // Returns 4
_cnt = count units group player; // Returns the number of units in the player group
_found = [1,9,8,3,4,4,4,5,6]; {_x==4} count _found; // Returns 3
_alive = {alive _x} count allUnits; // Returns the number of living units
_count = count ([[configFile]] >> "CfgVehicles")  

Additional Information

See also: forEach


Posted on April 28, 2007 - 13:49

This conditional count command only works if all the elements in the tested array are of the same Category Data Types as the tested element.
For example, the following code will created an error, since the elements are of different types (object, number, string): _arr=[player,100,"one"]; {_x=="one"} count _arr This one, on the other hand, where all elements are strings, just like the tested element, will return the correct result of 1: _arr=["one","two","three"]; {_x=="one"} count _arr

Posted on August 3, 2006 - 14:27
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


{alive _x} count units groupname