Garry's Mod Wiki

pairs

function, table, any pairs( table tab )

Description

Returns an iterator function(next) for a for loop that will return the values of the specified table in an arbitrary order.

In sequential tables like player.GetAll or ents.GetAll (and ents.Find* functions), it's more efficient to use ipairs or for iterator.

Arguments

1 table tab
The table to iterate over.

Returns

1 function
The iterator (next).
2 table
The table being iterated over.
3 any
nil (for the constructor).

Example

Iterates through all PlayerInitialSpawn hooks on the server and prints their unique identifiers and called function.

for k, v in pairs( hook.GetTable().PlayerInitialSpawn ) -- The custom name given in the second argument of the hook.Add function. -- Example : "myCustomSpawnFunc". print( "Unique identifier:", k ) -- The hook function. -- Example : "function: 0x3a3f2c80". print( "Called function:", v ) end
Output: A list of all hooks.

Page Links


Special Pages


Wikis

?

Render Time: 77ms

DB GetPage 4
Generate Html 13
SaveChanges (1) 46
Render Body 0
Render Sidebar 11