select: Difference between revisions
Jump to navigation
Jump to search
Killzone Kid (talk | contribs) (see also) |
No edit summary |
||
Line 110: | Line 110: | ||
<code>[0,1] [[select]] (56 > 40) // 1 | <code>[0,1] [[select]] (56 > 40) // 1 | ||
[0,1,2] [[select]] ((![[isNil]] "v") && [[false]]) // 0</code> | [0,1,2] [[select]] ((![[isNil]] "v") && [[false]]) // 0</code> | ||
<dd class="notedate">Posted on 14 juil, 2016 | |||
<dt class="note">'''[[User:Pierre MGI|Pierre MGI]]'''<dd class="note">You can substract array from array using select: | |||
<code>_array = [[1],[2],[3]]; _sub = [2]; | |||
_array - _sub // [[1],[2],[3]; | |||
_array select {!(_x isEqualTo _sub)} // [[1],[3]]; | |||
[[1],[2],[2],[2],[2],[3]] select {!(_x isEqualTo _sub)} // [[1],[3]]; | |||
</code> | |||
</dd> | </dd> | ||
</dl> | </dl> |
Revision as of 03:18, 14 July 2016
Description
- Description:
- Selects an element from an array, config entry from Config or substring from a string or a range from an array.
- Groups:
- Uncategorised
Syntax 1
- Syntax:
- array select index
- Parameters:
- array : Array
- index: Number - Index 0 denotes the first element, 1 the second, etc. If index has decimal places it gets rounded down for fractions less than or equal .5, otherwise it gets rounded up.
- Return Value:
- Anything
Syntax 2
- Syntax:
- array select boolean
- Parameters:
- array : Array
- boolean: Boolean - true => 1, false => 0
- Return Value:
- Anything
Syntax 3
- Syntax:
- config select index
- Parameters:
- config : Config
- index: Number - Index 0 denotes the first element, 1 the second, etc. If index has decimal places it gets rounded down for fractions less than or equal .5, otherwise it gets rounded up.
- Return Value:
- Config
Syntax 4
- Syntax:
- string select [start, length] (since ["Arma 3","Arma3",127,126674,"Development"])
- Parameters:
- string: String
- [start, length]: Array
- start: Number - String position to start selection from. 0 denotes the first character of the string, 1 the second, etc. If passed number has decimal places it gets rounded down for fractions less than or equal .5, otherwise it gets rounded up.
- length (optional): Number - Number of the string characters to select. If "length" is omitted, selection will be made from "start" to the end of the string.
- Return Value:
- String
Syntax 5
- Syntax:
- array select [start, count] (since ["Arma 3","Arma3",131,127272,"Development"])
- Parameters:
- array: Array
- [start, count]: Array
- start: Number - Array index to start selection from.
- count: Number - Number of array elements to select. If the selected range exceeds source array boundaries, selection will be made up to the last element of the array.
- Return Value:
- Array
Syntax 6
- Syntax:
- array select expression (since ["Arma 3","Arma3",155,133771,"Development"])
- Parameters:
- array: Array
- expression: Code - expression that is expected to return Boolean or Nothing. If true is returned, the original array value of currently tested element _x will be added to the output array
- Return Value:
- Array - array of all elements from the original array that satisfied expression condition
Examples
- Example 1:
[1,2,3,4] select 2; //result is 3 position player select 2; //result is Z coordinate of player position
- Example 2:
["", currentWeapon player] select alive player; //if dead "" is selected
- Example 3:
(configFile >> "cfgVehicles" >> typeOf vehicle player >> "Turrets") select 0 >> "gunnerAction";
- Example 4:
hint str ("japa is the man!" select [8]); //the man! hint str ("japa is the man!" select [0,7]); //japa is
- Example 5:
hint str ([1,2,3,4,5,6] select [1,4]); //[2,3,4,5]
- Example 6:
_even = [1,2,3,4,5,6,7,8,9,0] select {_x%2 == 0}; // returns [2, 4, 6, 8, 0]
Additional Information
- See also:
- selectRandomsetresizereverseinfindtoArraytoStringforEachcountdeleteAtdeleteRangeappendsortparamparamssplitStringjoinStringpushBackpushBackUniqueapply
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 3 March 2009
- General Barron
- When combined with the count command, this can be used to read all entries out of a config; even when you don't know exactly how many entries there will be. See the notes under count for more info.
- Posted on 27 Sep, 2013
- Killzone_Kid
- Rounding of fractions with select is not the same as when you use round command:
_roundThis = 0.5; hint str ([0,1] select _roundThis); //0 hint str round _roundThis; //1
- Posted on 30 May, 2014 - 1549
- ffur2007slx2_5
-
In ArmA3 ver 1.18, Boolean type supported. Which true defaulted as 1 and false as 0.
[0,1] select (56 > 40) // 1 [0,1,2] select ((!isNil "v") && false) // 0
- Posted on 14 juil, 2016
- Pierre MGI
- You can substract array from array using select:
_array = [[1],[2],[3]]; _sub = [2]; _array - _sub // [[1],[2],[3]; _array select {!(_x isEqualTo _sub)} // [[1],[3]]; [[1],[2],[2],[2],[2],[3]] select {!(_x isEqualTo _sub)} // [[1],[3]];
Bottom Section
- Posted on June 22, 2015 - 23:23 (UTC)
- Killzone Kid
-
Usually when select tries to pick up element out of range, Arma throws "division by zero" error. However there are exceptions. Basically as long as index of element you are selecting is less then or equal to array size, you will get no error.
[] select 0; //ok, result is nil [1,2,3] select 3; //ok, result is nil [1,2,3] select 4; //division by zero
Categories:
- Scripting Commands
- Introduced with Operation Flashpoint version 1.00
- Operation Flashpoint: New Scripting Commands
- Operation Flashpoint: Scripting Commands
- Command Group: Uncategorised
- Scripting Commands OFP 1.99
- Scripting Commands OFP 1.96
- Scripting Commands OFP 1.46
- Scripting Commands ArmA
- Command Group: Variables
- Scripting Commands ArmA2
- Scripting Commands Arma 3
- Scripting Commands Take On Helicopters