findIf: Difference between revisions
Jump to navigation
Jump to search
(Created page with "{{Command|= Comments ____________________________________________________________________________________________ | arma3dev |= Game name |1.81|= Game version ______________...") |
No edit summary |
||
Line 22: | Line 22: | ||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
|x1= <code>[unit1,unit2,unit3] [[ | |x1= <code>[unit1,unit2,unit3] [[findIf]] {!alive _x}; //return index of first dead unit</code> |= Example 1 | ||
|x2= <code>waitUntil{[unit1,unit2,unit3] [[findIf]] {alive _x} == -1}; //wait until all are dead, faster then count as it doesn't need to go through all elements unless all evals to false = are dead</code> |= Example 2 | |||
___________________________________________________________________________________________ | ___________________________________________________________________________________________ | ||
Revision as of 15:38, 6 March 2018
Description
- Description:
- Searches for an element within array for which the code evaluates to true. Returns the 0 based index on success or -1 if not found. Code on the right side of the command is evaluated for each element of the array, processed element can be referenced in code as _x.
NOTE: Because command findIf terminates as soon as it finds an element that fulfills the condition, it is more efficient then count in scenarios where you need to check for presence / absence of at least one element that evaluates to true. - Groups:
- Uncategorised
Syntax
- Syntax:
- array find code
- Parameters:
- array: Array - array to search in
- code: Code - code defining an element to find, processed element can be referenced within the code as _x
- Return Value:
- Number - 0 based position of the first array element for which the code evaluate to true, -1 if not found
Examples
- Example 1:
[unit1,unit2,unit3] findIf {!alive _x}; //return index of first dead unit
- Example 2:
waitUntil{[unit1,unit2,unit3] findIf {alive _x} == -1}; //wait until all are dead, faster then count as it doesn't need to go through all elements unless all evals to false = are dead
Additional Information
- See also:
- find
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
[[Category:Introduced with arma3dev version 1.81]][[ Category: arma3dev: New Scripting Commands | FINDIF]][[ Category: arma3dev: Scripting Commands | FINDIF]]