in: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Fix faulty example)
m (Add forEach example)
Line 14: Line 14:
| value [[in]] array |SYNTAX=
| value [[in]] array |SYNTAX=


|p1= value: [[Anything]] - any value (Arma 2 cannot  match [[Array]]) |PARAM1=
|p1= value: [[Anything]] - any value (cannot  match [[Array]] before {{arma3}}) |PARAM1=


|p2= array: [[Array]] - array of values |PARAM2=
|p2= array: [[Array]] - array of values |PARAM2=
Line 48: Line 48:
____________________________________________________________________________________________
____________________________________________________________________________________________


|x1 = <code>1 [[in]] [0, 1, 2]; {{cc|true}}</code> |Example 1=
|x1= <code>1 [[in]] [0, 1, 2]; {{cc|true}}</code> |Example 1=


|x2 = <code>[[private]] _myArray = ["Aaa", "AAa", "AAA"];
|x2= <code>[[private]] _myArray = ["Aaa", "AAa", "AAA"];


"aaa" [[in]] _myArray; {{cc|false}}
"aaa" [[in]] _myArray; {{cc|false}}
Line 57: Line 57:
{{cc|case-insensitive alternatives}}
{{cc|case-insensitive alternatives}}
_myArray [[findIf]] { _x == "aaa"; } != -1; {{cc|true}}
_myArray [[findIf]] { _x == "aaa"; } != -1; {{cc|true}}
{ [[_x]] == "aaa"; } [[count]] _myArray > 0; {{cc|true, less performant but valid before [[findIf]]}}</code> |Example2=
 
({
[[if]] ([[_x]] == "aaa") [[exitWith]] { [[_forEachIndex]] };
-1
} [[forEach]] _myArray) != -1; {{cc|true, less performant but valid before [[findIf]]}}
 
{ [[if]] ([[_x]] == "aaa") [[exitWith]] {1} } [[count]] _myArray > 0; {{cc|true}}
 
{ [[_x]] == "aaa"; } [[count]] _myArray > 0; {{cc|true, worst performance}}
{{cc|only option available in OFP}}</code> |Example2=


|x3= Arma 3:<code>[1,2,3] [[in]] <nowiki>[</nowiki>[1,2,3], [4,5,6]]; {{cc|true}}</code> |Example3=
|x3= Arma 3:<code>[1,2,3] [[in]] <nowiki>[</nowiki>[1,2,3], [4,5,6]]; {{cc|true}}</code> |Example3=

Revision as of 20:07, 16 September 2019

Hover & click on the images for description

Description

Description:
Checks whether value is in array, unit is in vehicle, position is inside location or string is part of other string.
String comparison is case-sensitive (see Examples 2, 6).
Arma 3
Since Arma 3 you can test for arrays within arrays.
Groups:
Uncategorised

Syntax 1

Syntax:
value in array
Parameters:
value: Anything - any value (cannot match Array before Arma 3)
array: Array - array of values
Return Value:
Boolean

Syntax 2

Syntax:
unit in vehicle
Parameters:
unit: Object - person
vehicle: Object - transport
Return Value:
Boolean

Syntax 3

Syntax:
position in location        (Since Arma 3)
Parameters:
position: Array - format Position2D or Position3D
location: Location
Return Value:
Boolean

Syntax 4

Syntax:
needle in haystack        (Since Arma 3 v1.95.146032)
Parameters:
needle: String - string to search for
haystack: String - string to search in
Return Value:
Boolean

Examples

Example 1:
1 in [0, 1, 2]; // true
Example 2:
private _myArray = ["Aaa", "AAa", "AAA"]; "aaa" in _myArray; // false "AAa" in _myArray; // true // case-insensitive alternatives _myArray findIf { _x == "aaa"; } != -1; // true ({ if (_x == "aaa") exitWith { _forEachIndex }; -1 } forEach _myArray) != -1; // true, less performant but valid before findIf { if (_x == "aaa") exitWith {1} } count _myArray > 0; // true { _x == "aaa"; } count _myArray > 0; // true, worst performance // only option available in OFP
Example 3:
Arma 3:[1,2,3] in [[1,2,3], [4,5,6]]; // true
Example 4:
_isInCar = player in car;
Example 5:
_isInside = [1000,2000,0] in myLocation;
Example 6:
_isInString = "foo" in "foobar"; // true _isInString = "Foo" in "foobar"; // false

Additional Information

See also:
inPolygoninAreasetresizereversepushBackpushBackUniqueapplyselectfindtoArraytoStringforEachcountdeleteAtdeleteRangeappendsortparamparamsarrayIntersectsplitStringjoinString

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 August 27, 2017 - 11:33 (UTC)
SilentSpike
The Object syntax of in might not behave as you would expect (e.g. it would always return true) when both parameters are the same object . It serves as a quick method of checking if a unit is mounted: private _onFoot = _unit in _unit;

Bottom Section