Garry's Mod Wiki


  any select( any parameter, vararg vararg )


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


1 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.
2 vararg vararg
The vararg. These are the values from which you want to select.


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


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 "#")


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


This prints the last 2 arguments passed

print( select( -2, 1, 2, 3, 4, 5 ) )
Output: "4 5" in the console