table.insert

From GMod Wiki

Jump to: navigation, search
Function
Syntax table.insert( Table table, [ Integer Position], Var addition )
Where is this used?
Description:
Adds a value into a table, either in a specified spot or on to the end.
Returns: Number index
Part of Library: Table
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Table.insert]Table.insert [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Example

DescriptionInsert a few values into a table.
Used onNewerShared.png
Code
test_table = {"this","that","and the other"} // Define the table.
 
table.insert(test_table,"hello") // Add "hello" to the end.
print(table.concat(test_table,", ")) // Prints "this, that, and the other, hello" to the console.
 
table.insert(test_table,2,"whoa!") // Add "whoa!" in between "this" and "that".
print(table.concat(test_table,", ")) // Prints "this, whoa!, that, and the other, hello" to the console.
OutputPrints a couple strings of the table as it is added to.


Additional Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox