You are working with multidimensional arrays when you have sub-tables. You can index a sub table like below.
local tab = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
}
for i, v in next, tab do
print(i, v)
for n, k in next, v do
print(">", n, k)
end
end
-- 1 table: 000001
-- > 1 1
-- > 2 2
-- > 3 3
-- 2 table: 000002
-- > 1 4
-- > 2 5
-- > 3 6
-- 3 table: 000003
-- > 1 7
-- > 2 8
-- > 3 9
To index the table above without for loops, you can use the []'s.
print(tab[1][1]) --> 1
print(tab[1][2]) --> 2
print(tab[2][1]) --> 4
print(tab[2][2]) --> 5
You are NOT restricted to number indices. You can use strings and a special way to index with them.
local tab = {
x = 5,
y = 10,
[3] = 15
}
print(tab.x, tab["y"], tab[3]) --> 5 10 15