select

From Garry's Mod
Jump to: navigation, search
 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