1
votes
local coordTable = {
    {loc={{1447, -2287, 13}, {0, 0, 3}, {100, -2000, 13}}, colour={255, 255, 255}},
}

Hi,

I'm trying to get each of the values from within loc. So, for each tables within loc, I want the value of the three numbers inside. I'm not sure if I'm explaining correctly.

Sort of like this issue, but slightly more complex. I'm able to get the first table within loc using the same method in the issue linked above, but not the other tables.

Any help would be appreciated. Thank you.

1
What part do you need help with? coordTable is an array of coordinates, and the loc of each coordinate is an array of length-3 arrays. - Colonel Thirty Two
I basically need to get the 3 numbers from each table within loc. - nokizorque

1 Answers

5
votes

Perhaps this helps you make sense of how to traverse the data:

for k,v in ipairs(coordTable[1].loc) do
    for i,w in ipairs(v) do
        print(k,i,w)
    end
end

Or that, if you always have three numbers in each subtable:

for k,v in ipairs(coordTable[1].loc) do
    print(v[1],v[2],v[3])
end

To get the three numbers in the second subtable directly, use

print(coordTable[1].loc[2][1],coordTable[1].loc[2][2],coordTable[1].loc[2][3])