count: Difference between revisions
Jump to navigation
Jump to search
m (note formate) |
m (note formate) |
||
Line 59: | Line 59: | ||
<dl class="command_description"> | <dl class="command_description"> | ||
<!-- Note Section BEGIN --> | <!-- Note Section BEGIN --> | ||
<dd class="notedate">Posted on April 28, 2007 - 13:49 | <dd class="notedate">Posted on April 28, 2007 - 13:49 | ||
<dt class="note">'''[[User:Kronzky|Kronzky]]'''<dd class="note"> | <dt class="note">'''[[User:Kronzky|Kronzky]]'''<dd class="note"> | ||
This conditional count command ''only'' works if all the elements in the tested array are of the same [[Data Types|type]] as the tested element.<br> | This conditional count command ''only'' works if all the elements in the tested array are of the same [[Data Types|type]] as the tested element.<br> | ||
For example, the following code will created an error, since the elements are of different types (object, number, string): | For example, the following code will created an error, since the elements are of different types (object, number, string): | ||
<code>_arr= [ [[player]],100,"one"]; {_x == "one"} [[count]] _arr;</code> | <code>_arr = [ [[player]],100,"one"]; {_x == "one"} [[count]] _arr;</code> | ||
This one, on the other hand, where all elements are strings, just like the tested element, will return the correct result of 1: | This one, on the other hand, where all elements are strings, just like the tested element, will return the correct result of 1: | ||
<code>_arr = ["one","two","three"]; {_x == "one"} [[count]] _arr;</code> | <code>_arr = ["one","two","three"]; {_x == "one"} [[count]] _arr;</code> | ||
Line 72: | Line 70: | ||
<dd class="notedate">Posted on August 3, 2006 - 14:27 | <dd class="notedate">Posted on August 3, 2006 - 14:27 | ||
<dt class="note">'''[[User:Hardrock|hardrock]]'''<dd class="note">''Notes from before the conversion:'' | <dt class="note">'''[[User:Hardrock|hardrock]]'''<dd class="note">''Notes from before the conversion:'' | ||
Use this to calculate how many "M16" mags a soldier has left. | Use this to calculate how many "M16" mags a soldier has left. | ||
<code>{_x <nowiki>==</nowiki> "M16"} [[count]] [[magazines]] soldier1;</code> | <code>{_x <nowiki>==</nowiki> "M16"} [[count]] [[magazines]] soldier1;</code> | ||
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: | 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: | ||
<code>{[[alive]] _x} [[count]] [[units]] [[group]] [[player]];</code> | <code>{[[alive]] _x} [[count]] [[units]] [[group]] [[player]];</code> | ||
or | or | ||
<code>{[[alive]] _x} [[count]] [[units]] groupname;</code> | <code>{[[alive]] _x} [[count]] [[units]] groupname;</code> | ||
<!-- Note Section END --> | <!-- Note Section END --> |
Revision as of 03:40, 4 August 2014
Description
- Description:
- Returns a count for either
- the number of elements in array
- the number of elements in array for which given condition is true
- the number of sub-entries in a config object
- Groups:
- Uncategorised
Syntax
- Syntax:
- condition count array
- Parameters:
- condition: (optional) Code that must return true to be counted.
The variable _x will contain the currently tested element. - array: Array
- Return Value:
- Number
Alternative Syntax
Examples
- Example 1:
_cnt = count [0, 0, 1, 2]; // returns 4
- Example 2:
_cnt = count units group player; // returns number of units in player group
- Example 3:
_fnd = [1, 9, 8, 3, 4, 4, 4, 5, 6]; { _x == 4; } count _fnd; // returns 3
- Example 4:
_alive = { alive _x; } count allUnits; // returns the number of living units
_cnt = count (configFile >> "CfgVehicles");
Additional Information
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 April 28, 2007 - 13:49
- Kronzky
-
This conditional count command only works if all the elements in the tested array are of the same type 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
- 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
Categories:
- Scripting Commands
- Introduced with Operation Flashpoint version 1.00
- Operation Flashpoint: New Scripting Commands
- Operation Flashpoint: Scripting Commands
- Command Group: Uncategorised
- Scripting Commands OFP 1.96
- Scripting Commands OFP 1.46
- Scripting Commands ArmA
- Command Group: Variables
- Scripting Commands ArmA2
- Scripting Commands Arma 3
- Scripting Commands Take On Helicopters