Garry's Mod Wiki

list

The list library allows you add and retrieve values to and from lists. The list library is basically a fancy wrapper for a table, but with much more limited functionality.

It is used extensively in the built-in Sandbox gamemode for addon-extensible lists of things (list of wheel models, list of thruster effects, etc) , without using global tables for this task.

See Default Lists for a page of default Sandbox lists.

Methods

number list.Add( string identifier, any item )
Adds an item to a named list
boolean list.Contains( string list, any value )
Returns true if the list contains the value. (as a value - not a key) For a function that looks for a key and not a value see list.HasEntry.
table list.Get( string identifier )
Returns a copy of the list stored at identifier Warning: This function uses table.Copy which can be very slow for larger lists. You should avoid calling it repeatedly or in performance sensitive hooks such as GM:Think. Where possible you should use the much faster helper functions: list.Contains, list.HasEntry, or list.GetEntry There is also the more dangerous option of calling list.GetForEdit to get the unprotected list if you absolutely must iterate through it in a think hook.
any or nil list.GetEntry( string list, string key )
Returns a copy of the entry in the list list with key key.
table list.GetForEdit( string identifier, boolean dontCreate = false )
Returns the actual table of the list stored at identifier. Modifying this will affect the stored list
Returns a list of all lists currently in use.
boolean list.HasEntry( string list, any key )
Returns true if the list contains the given key. For a function that looks for values and not keys see list.Contains.
list.RemoveEntry( string list, string key )
Removes a single entry from the list list with key key. This is equivalent to list.Set( myList, myKey, nil ).
list.Set( string identifier, any key, any item )
Sets a specific position in the named list to a value.