in
{{RV|type=command
|game1= ofp |version1= 1.00
|game2= ofpe |version2= 1.00
|game3= arma1 |version3= 1.00
|game4= arma2 |version4= 1.00
|game5= arma2oa |version5= 1.50
|game6= tkoh |version6= 1.00
|game7= arma3 |version7= 0.50
|gr1= Strings
|gr2= Arrays
|gr3= Locations
|gr4= HashMap
|gr5= Unit Control
|descr= Checks whether value is in array, unit is in vehicle, position is inside location or ANSI string is part of other ANSI string. If Unicode support is desired, see forceUnicode.
|s1= value in array
|p1= value: Anything - Any value (cannot match Array before Arma 3)
|p2= array: Array - Array of values
|r1= Boolean
|s2= unit in vehicle
|p21= unit: Object - Entity person
|p22= vehicle: Object - Entity vehicle
|r2= Boolean
|s3= position in location
|s3since= arma3 0.50
|p41= position: Array - Format Position2D or Position3D
|p42= location: Location
|r3= Boolean
|s4= needle in haystack
|s4since= arma3 1.96
|p61= needle: String - String to search for
|p62= haystack: String - String to search in
|r4= Boolean
|s5= key in hashMap
|s5since= arma3 2.02
|p81= key: HashMapKey
|p82= hashMap : HashMap
|r5= Boolean
|x1= 1 in [0, 1, 2]; // true
|x2= 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
|x3= [1,2,3] in [[1,2,3], [4,5,6]]; // true - {{arma3 only}}
|x4= _isInCar = player in car;
|x5= _isInside = [1000,2000,0] in myLocation;
|x6= _isInString = "foo" in "foobar"; // true
_isInString = "Foo" in "foobar"; // false
|x7= private _onFoot = _unit in _unit;
// vehicle _unit == _unit works
// isNull objectParent _unit is even faster
|seealso= inPolygon inArea find findIf toArray forceUnicode }}
- Posted on October 8, 2019 - 21:08 (UTC)
- Lou Montana
- From a description note:
<unit> in <vehicle> literally does this: vehicle <unit> == <vehicle>. If <vehicle> is the same as <unit> the expression will return true for when the <unit> is on foot and false for when <unit> is in vehicle (see example 7 & 8).