count
Jump to navigation
Jump to search
Description
- Description:
- Can be used to count:
- The number of elements in an array (returns the already internally known array size)
- The number of elements in an array matching the condition
- The number of sub-entries in a config entry
- 1.28 The number of characters in an ANSI string
- Groups:
- ArraysStringsConfigHashMap
Syntax
Alternative Syntax
- Syntax:
- condition count array
- Parameters:
- condition: Code - condition that must return true for the tested element to be counted. The variable _x will contain the currently tested element
- array: Array
- Return Value:
- Number
Examples
- Example 1:
- Example 2:
- Example 3:
- Example 4:
- Example 5:
Additional Information
- See also:
- apply select in find countFriendly countEnemy countUnknown countSide countType findIf forceUnicode
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
- Posted on Aug 03, 2006 - 14:27 (UTC)
-
Notes from before the conversion:
Use this to calculate how many "M16" mags a soldier has left. 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: or
- Posted on Dec 15, 2014 - 00:01 (UTC)
-
count can be (ab)used for a very fast and simple check if at least one element in an array fulfills a certain condition:
This code will exit the count loop as soon as it finds an element fulfilling the condition, leaving the count with the value of 1, hence make the larger if-condition be true.
If no array element fulfills the condition, the count will be 0 and the if-condition will be false.
- Posted on Dec 29, 2014 - 21:23 (UTC)
- Quit loop at first fulfilled condition (same as above but faster):
- Posted on Jan 02, 2015 - 22:32 (UTC)
- Using exitWith inside a count loop will overwrite the default functionality and make count return whatever the exitWith returns:
- Posted on Aug 22, 2016 - 19:41 (UTC)
-
With the alternative syntax each iteration should result in an interior return of bool or nothing. Example:
lbAdd returns a number, so this throws "Error Type Number, expected Bool". Tested in A2OA 1.63.131129
Categories:
- Scripting Commands
- Introduced with Operation Flashpoint version 1.00
- Operation Flashpoint: New Scripting Commands
- Operation Flashpoint: Scripting Commands
- Operation Flashpoint: Elite: Scripting Commands
- ArmA: Armed Assault: Scripting Commands
- Arma 2: Scripting Commands
- Arma 2: Operation Arrowhead: Scripting Commands
- Take On Helicopters: Scripting Commands
- Arma 3: Scripting Commands
- Command Group: Arrays
- Command Group: Strings
- Command Group: Config
- Command Group: HashMap