Page tree
Skip to end of metadata
Go to start of metadata



Introduced in

Version:1.00

Description

Description:

Selects an index element of an array or configuration object. An index of 0 denotes the first element, 1 the second, and so on.

If an index has decimal places, it gets rounded down for fractions less than 0.5. Otherwise, it gets rounded up. Be aware that mathematical operators take preference over the argument used with select.

Syntax

Syntax:array select index
Parameters:
  • array : Array - Array to check.
  • index: Number - Array index.
Return Value:Any Value

Alternative Syntax

Syntax:config select index
Parameters:
  • config: Config-2 - Configuration to check.
  • index: Number - Configuration index.
Return Value:Config-2

Examples

Examples:
[10,20,30,40] select 2 + 1; // selects the 3rd element, returning 40
([10,20,30,40] select 2) + 1; // adds 1 to the 2nd element, returning 31
[1,2,3,4] select 2  // the result is 3
position player select 2 // result is Z coordinate of player position
(configFile >> "CfgVehicles") select 0

Additional Information

See also: count
Multiplayer:
Problems:

Notes






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. --General Barron 02:02, 3 March 2009 (CET)