Foxat wrote:Heyyyy,
I'm new to coding in general. i can't grasp and comprehend the concept of a lua table though.
Can someone please explain or provide a link that explains tables.
SHANKS
Look this code:
Code: Select all
myTable = {}
for row = 1, 10 do
myTable[row] = row
end
if you represent myTable after running that code, it will look like:
Code: Select all
myTable = {1,
2,
3,
4,
5,
6,
7,
8,
9,
10
}
And to access any element you can do this:
myTable[2] = 2
Now something more complex:
Code: Select all
myTable = {}
for row = 1, 10 do
myTable[row] = {}
for col = 1, 4 do
myTable[row][col] = row .. " " .. col
end
end
That table would be :
Code: Select all
myTable = { {"1 1", "1 2", "1 3", "1 4"},
{"2 1", "2 2", "2 3", "2 4"},
{"3 1", "3 2", "3 3", "3 4"},
{"4 1", "4 2", "4 3", "4 4"},
{"5 1", "5 2", "5 3", "5 4"},
{"6 1", "6 2", "6 3", "6 4"},
{"7 1", "7 2", "7 3", "7 4"},
{"8 1", "8 2", "8 3", "8 4"},
{"9 1", "9 2", "9 3", "9 4"},
{"10 1", "10 2", "10 3", "10 4"},
}
Getting elements from this will be like this:
myTable[3][2] = "3 2"
A good way to build tables without messing the dimensions is to use row and col variables in the for...next instead i and j, so it is more visual and less confusing.
Hope this is helpful.