Global/select

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(Grammar fix, telling to not using negative number if you want to make it jit compilable)
m (Better wording)
 
Line 12: Line 12:
 
* If it's a string and starts with "#", the function will return the amount of values in the vararg (ignoring the rest of the string).
 
* If it's a string and starts with "#", the function will return the amount of values in the vararg (ignoring the rest of the string).
 
* If it's a positive number, the function will return all values starting from the given index.
 
* If it's a positive number, the function will return all values starting from the given index.
* If the number is negative, it will return the amount specified from the end instead of the beginning; Using this last mode will make the whole function non jit-compilable.
+
* If the number is negative, it will return the amount specified from the end instead of the beginning. This mode will not be compiled by LuaJIT.
 
}}
 
}}
 
{{Arg
 
{{Arg

Latest revision as of 17:11, 18 November 2019

 select( )

Contents

Description

Used to select single values from a vararg or get the count of values in it.

Arguments

any parameter

Can be a number or string.

  • If it's a string and starts with "#", the function will return the amount of values in the vararg (ignoring the rest of the string).
  • If it's a positive number, the function will return all values starting from the given index.
  • If the number is negative, it will return the amount specified from the end instead of the beginning. This mode will not be compiled by LuaJIT.

Arguments

vararg vararg

The vararg. These are the values from which you want to select.

Returns

any

Returns a number or vararg, depending on the select method.

Examples

Example

This code shows how it works with the "#" modifier:

print( select( '#', 'a', true, false, {}, 1 ) )

Output:

"5", which is the count of parameters passed excluding the modifier (the "#")

Examples

Example

This prints from the 2nd vararg passed to the last

print( select( 2, 1, 2, 3, 4, 5 ) )

Output:

"2 3 4 5" in the console

Examples

Example

This prints the last 2 arguments passed

print( select( -2, 1, 2, 3, 4, 5 ) )

Output:

"4 5" in the console
Personal tools
Navigation