table.IsSequential

From GMod Wiki

Jump to: navigation, search
Function
Syntax table.IsSequential( Table Table )
Where is this used?
Description:
Returns true if all of a table's keys are sequential and numerical.
Returns: Boolean
Part of Library: Table
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Table.IsSequential]Table.IsSequential [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]


Examples

DescriptionChecks to see if various tables are sequential/numerical.
Used onNewerShared.png
Code
local SequentialTable = {
    "string",
    {},
    193
}
//The above will define a table with the following keys and values:
//1 = "string"
//2 = {}
//3 = 193
 
local NoneSequentialTable = {
    "string" = "string",
    [504] = {},
    "another string" = 193
}
//The above will define a table with the following keys and values:
//"string" = "string"
//504 = {}
//"another string" = 193
 
local MostlySequentialTable = {
    "string",
    "another string",
    {},
    5 = 193,
}
//The above will define a table with the following keys and values:
//1 = "string"
//2 = "another string"
//3 = {}
//5 = 193
 
print(table.IsSequential(SequentialTable))
//True, as all of the table's keys are sequential and numerical.
print(table.IsSequential(NoneSequentialTable))
//False, as the table's keys are not numerical or sequential.
print(table.IsSequential(MostlySequentialTable))
//False, even though the keys are all numerical, one of the keys does not follow the sequence.
 
OutputN/A


Additional Notes

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox