1
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.

Community
  • 1
  • 1
nokizorque
  • 57
  • 1
  • 6

1 Answers1

5

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])
lhf
  • 70,581
  • 9
  • 108
  • 149
  • "111447 12-2287 1313 210 220 233 31100 32-2000 3313 111447 12-2287 1313 210 220 233 31100 32-2000 3313" It returns the numbers, but in a weird way. – nokizorque Feb 28 '15 at 05:12
  • @user3549165, weird how? Anyway, perhaps my edited answer is clearer now. – lhf Feb 28 '15 at 11:35