There's a couple ways of doing this:
Option #1:
myTable = {
{"Dogs", "Cats", "Bunnies"},
{2,3,10}
}
print(myTable[1])
print(myTable[1][2])
for index, innerTable in ipairs(myTable)do
print(innerTable, " ", index)
for itemIndex, item in ipairs(innerTable)do
print(item, " ", itemIndex)
end
end
Option #2:
myTable = {
Animals = {"Dogs", "Cats", "Bunnies"},
SpecialNumbers = {2,3,10}
}
for i, v in ipairs(myTable.Animals)do
print(v)
end
for i, v in ipairs(myTable.SpecialNumbers)do
print(v)
end
Option #1 is nice when you want to loop through everything in the table, which is rarely the case when it comes to having tables inside of tables.
Option #2 is nice because instead of looping, you can instantly get the table inside myTable without any added steps, which is a lot quicker when you have a big game with a lot of tables.
1 comment
tbl1[index1][index2]