teaching myself lua and trying to work out how to access keys and values in nested tables when you have an array of them. If I had for example the following table:
local coupledNumbers = {}
local a = 10
for i = 1, 12 do
for j = 1, 12 do
table.insert(coupledNumbers, {ID = a, result = i*j})
a = a + 10
end
end
This loop will give me the keys (1 to 144)
for k, v in pairs (coupledNumbers) do
print (k)
end
This loop will give me the values (something along the lines of: table: 0xc475fce7d82c60ea)
for k, v in pairs (coupledNumbers) do
print (v)
end
My question is how do I get into the values inside the table?
how do I get ID and result. I thought something like that would work:
print (coupledNumbers[1].["ID"])
or
print (coupledNumbers[1].["result"])
But it gives an error.