count: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 1: Line 1:
[[Category:Scripting Commands|COUNT]]
{{Command|= Comments
[[Category:Scripting Commands OFP 1.96|COUNT]]
____________________________________________________________________________________________
[[Category:Scripting Commands OFP 1.46|COUNT]]
[[Category:Scripting Commands ArmA|COUNT]]


| ofp |= Game name


<h2 style="color:#000066">'''''condition'' count ''array'''''</h2>
|1.00|= Game version


|arg= local |= Arguments in MP
____________________________________________________________________________________________


'''Operand types:'''
| Returns the number of elements in an array |= Description
____________________________________________________________________________________________


'''condition:''' [[Code]]
| '''count''' array condition '''count''' array |= Syntax


'''array:''' [[Array]]
|p1= array: [[Array]] |= Parameter 1


'''Type of returned value:'''
|p2= condition: [[String]] - the condition which should be checked. Inside it "_x" stands for each array item. |= Parameter 2


[[Number]]
|p3= array: [[Array]] |= Parameter 3


'''Description:'''
| [[Integer]] -  [[Integer]] |= Return value
____________________________________________________________________________________________
 
|x1= <pre>_array = [soldier1, soldier2, soldier3]
count_array</pre>


Counts elements in '''array''' for which given '''condition''' is [[true]].
returns 3The second usage of count counts how often a condition applies in an array.


It is calculated as follows:
<pre>_array = [1,2,2,3,4,4,4,5,6]
{_x==2} count_array</pre>


Set '''count''' to 0.<br>
returns 2 |= Example 1
For each element of '''array''' assign element as '''_x''' and evaluate '''condition''' expression.<br>
____________________________________________________________________________________________
If [[true]] increase '''count'''.


| [[forEach]] |= See also


'''Example:'''
}}


{'''_x''' > 2} '''count''' [0, 1, 1, 2, 3, 3] ...... Result is 2
<h3 style="display:none">Notes</h3>
<dl class="command_description">
<!-- Note Section BEGIN -->


<!-- Note Section END -->
</dl>


In general:<br>
<h3 style="display:none">Bottom Section</h3>
{condition} '''count''' array <br>
Old Notes (temporary):
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:'''
(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


'''count''' [0, 1, 1, 2, 3, 3] ...... Result is 6
[[Category:Scripting Commands|COUNT]]
 
[[Category:Scripting Commands OFP 1.96|COUNT]]
 
[[Category:Scripting Commands OFP 1.46|COUNT]]
 
[[Category:Scripting Commands ArmA|COUNT]]
'''Comments:'''
 
(1) Use this to calculate how many '''"M16"''' mags a soldier has left.
 
("'''_x''' == {M16}" '''count''' [[magazines]] soldier1)<br>
 
 
 
(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

Revision as of 00:02, 2 August 2006

Hover & click on the images for description

Description

Description:
Returns the number of elements in an array
Groups:
Uncategorised

Syntax

Syntax:
count array condition count array
Parameters:
array: Array
condition: String - the condition which should be checked. Inside it "_x" stands for each array item.
array: Array
Return Value:
Integer - Integer

Examples

Example 1:
_array = [soldier1, soldier2, soldier3]
count_array

returns 3The second usage of count counts how often a condition applies in an array.

_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

Bottom Section

Old Notes (temporary):

(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