Originally posted by HobbsyJr
View Post
Announcement
Collapse
No announcement yet.
Table questions
Collapse
X
-
-
-
Tables contain values, each value has an index to describe where it is in the table.
if you don't set any indexes they are set automatically.
E.g
tMyTable = {"Fred", "Bob", "Jim", "Kingzooly"}
the indexes are automatically set to 1, 2, 3, 4 etc...
setting custom indexes is written like this
tMyTable = {59="Fred", 67="Bob"}.
Using a for loop the way you have shown the x would be the index and the j would be the value. So in my cutom index example:
Code:for x,j in pairs(tMyTable) do -- Some Stuff end
In your example:
TableName.Subtable = { [4] = { Name = '', Sec = '' } [89] = { Name = '', Sec = '' }
You have tables inside a table so the for loop would execute differently depending on which table you referenced.
I would suggest using:
Code:for x,j in pairs(AnyTableYouFancy) do Dialog.Message(x, j); end
Hope this helps
Leave a comment:
-
-
Table questions
Hey there all
I have a table
Code:TableName.Subtable = { [4] = { Name = '', Sec = '' }, [89] = { Name = '', Sec = '' }
and they don't have some numbers in it
like 4,7,12,89
I also need to return that number
so when I loop throw
Code:for x, j in pairs() do end
Tags: None
-
Leave a comment: