table.getn
From GMod Wiki
Revision as of 21:18, 2 November 2009 by Crazy Quebecer (Talk | contribs)
This function is deprecated in Lua version 5.1. Please use the hash ('#') operator to get the size of a table instead. |
Function | |
Syntax |
table.getn( Table table ) Where is this used? |
Description: | |
Returns the highest consecutive numerical index from 1 in a table. Returns 0 if there are no numerical indexes in the table. See Examples for a simplified explanation. | |
Returns: | Number |
Part of Library: | Table |
Realm: | |
BBCode Link: | [b][url=http://wiki.garrysmod.com/?title=Table.getn]Table.getn [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] |
Example
Additional Notes
- Use of the Length_Operator (#) calls this function. That is, #tableName is the same thing as table.getn(tableName)
- This function is best for determining the size of your table if you know it only has number indexes, and is packed in the normal fashion (1, 2, 3, 4, 5, 6, 7) as opposed to irregular fashions (1, 2, 4, 15, 1539). Tables that have things added to them with table.insert are sorted in normal fashion, for instance, so table.getn would be best for determining how big the table is.
- If your table is sorted irregularly (1,5,7,9,10) or uses something non numerical like strings for indexes ("test","test two","test three", 1, 2, 3, 4), but you want to know how many things are in the table total, use table.Count.
- This function gets the highest consecutive index (IE, 1,2,3,4,5,6,...,303). If you want to get the highest numerical index in a table non-consecutively (IE, 1,2,3,4,5,6,...,303), use table.maxn.