findIf

From Bohemia Interactive Community
Jump to: navigation, search
Introduced with Arma 3 version 1.82
  

Click on the images for descriptions

Introduced in

Game:
Arma 3
Version:
1.82

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.

Syntax

Syntax:
array findIf 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:
//two ways how to 'wait for all units to be dead': waitUntil { [unit1,unit2,unit3] findIf {alive _x} == -1 }; //fast, terminates as soon as it finds alive unit waitUntil { {alive _x} count [unit1,unit2,unit3] == 0 }; //slow, always goes through all array elements

Additional Information

Multiplayer:
-
See also:
find count

Notes

Only post proven facts here. Report bugs on the feedback tracker. Use the talk page or the forums for discussions.
Add New Note | How To

Notes

Bottom Section