table.Count

From GMod Wiki

Jump to: navigation, search
Function
Syntax table.Count( Table )
Where is this used?
Description:
Gets the total number of keys in a table - including both integer-keys and string-keys.
Returns: Integer The number of keys in the table.
Part of Library: Table
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Table.Count]Table.Count [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Example

DescriptionPrints a few various conditions involving table.Count and a table.
Used onNewerShared.png
Code
 
test_table = {"this","that","and the other"} // Define the table.
print(table.Count(test_table)) // Prints "3" to the console, how many keys are within test_table.
table.insert(test_table,"hello") // Inserts a new value.
print(table.Count(test_table)) // Last addition is now 4.
test_table[0] = "test"
test_table[-1] = "Negative number."
print(table.Count(test_table)) // Prints 6, 0 and -1 are counted.
test_table["hello"] = "test"
print(table.Count(test_table)) // Prints 7.
 
OutputFour numbers to the console of different situations in the script.


Additional Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox