findIf: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "{{Command " to "{{RV|type=command ")
m (Text replacement - "\{\{ *codecomment *\| *\/\/ *([^ ]+) *\}\} " to "{{cc|$1}}")
Line 22: Line 22:
   
   
|x1= <code>[unit1, unit2, unit3] [[findIf]] {[[not]] [[alive]] [[_x]]}; {{codecomment|// return index of the first dead unit)}}</code>
|x1= <code>[unit1, unit2, unit3] [[findIf]] {[[not]] [[alive]] [[_x]]}; {{codecomment|// return index of the first dead unit)}}</code>
|x2= <code>{{codecomment|// two ways how to 'wait for all units to be dead':}}
|x2= <code>{{cc| two ways how to 'wait for all units to be dead':}}[[waitUntil]] { [unit1, unit2, unit3] [[findIf]] {[[alive]] [[_x]]} == -1 }; {{cc| fast, terminates as soon as it finds a living unit}}[[waitUntil]] { {[[alive]] [[_x]]} [[count]] [unit1, unit2, unit3] == 0 }; {{codecomment|// slow, always goes through all array elements}}</code>
[[waitUntil]] { [unit1, unit2, unit3] [[findIf]] {[[alive]] [[_x]]} == -1 }; {{codecomment|// fast, terminates as soon as it finds a living unit}}
[[waitUntil]] { {[[alive]] [[_x]]} [[count]] [unit1, unit2, unit3] == 0 }; {{codecomment|// slow, always goes through all array elements}}</code>


| [[find]] [[count]]
| [[find]] [[count]]

Revision as of 17:31, 29 January 2021

Hover & click on the images for description

Description

Description:
Description needed
Groups:
Arrays

Syntax

Syntax:
Syntax needed
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:
Return value needed

Examples

Example 1:
[unit1, unit2, unit3] findIf {not alive _x}; // return index of the 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 a living unitwaitUntil { {alive _x} count [unit1, unit2, unit3] == 0 }; // slow, always goes through all array elements

Additional Information

See also:
See also needed

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