Garry's Mod Wiki

TypeID

  number TypeID( any variable )

Description

Gets the associated type ID of the variable. Unlike type, this does not work with no value - an argument must be provided.

This will return TYPE_TABLE for Color objects.
All subclasses of Entity will return TYPE_ENTITY.
This returns garbage for _LOADLIB objects.
This returns TYPE_NIL for protos.

Arguments

1 any variable
The variable to get the type ID of.

Returns

1 number
The type ID of the variable. See the TYPE enum.

Example

Check the variable return on a few types.

MsgN( TypeID( "Hello" ) ) MsgN( TypeID( function( ) end ) ) MsgN( TypeID( { } ) ) MsgN( TypeID( 80 ) ) MsgN( TypeID( false ) )
Output:
4 (TYPE_STRING) 6 (TYPE_FUNCTION) 5 (TYPE_TABLE) 3 (TYPE_NUMBER) 1 (TYPE_BOOL)

Example

Show output of a vararg.

-- This should output whatever you put in the first argument. local function Example( ... ) MsgN( TypeID( ... ) ) end Example( 1, "Hello" ) -- TYPE_NUMBER Example( "Hello", 1 ) -- TYPE_STRING -- This should output the table of data in a vararg. local function Example2( ... ) for k,v in pairs( { ... } ) do MsgN( TypeID( v ) ) end end Example2( "Hello", 1, { } ) -- TYPE_STRING, TYPE_NUMBER, TYPE_TABLE
Output:
3 (TYPE_NUMBER) 4 (TYPE_STRING) 4 (TYPE_STRING) 3 (TYPE_NUMBER) 5 (TYPE_TABLE)