Lua Nested Table Getting Elements
lua, lua-table
Solution
for i= 2, 4 do
local width = t1[draw.ID]["col" .. i] --draw.ID is got elsewhere
end
Problem
I have a nested table like so: ``` t1 ={} t1[1] = {col1=1,col2=1,col3=1,col4=1} t1[2] = {col1=1,col2=1,col3=1,col4=1} t1[3] = {col1=1,col2=1,col3=1,col4=1} t1[4] = {col1=1,col2=1,col3=1,col4=1} ``` it's actually much larger with 250 items in t1 and 30 items per nested table so what I want to do is loop through and get sub table values like this: ``` for i = 2, 4 do local width = t1[draw.ID].col1 --draw.ID is got elsewhere end ``` but changing the number part of `.col1` to the `i` part so when it loops through it gets: ``` t1[draw.ID].col2 t1[draw.ID].col3 t1[draw.ID].col4 ``` I'm using Lua 5.1.