I am not 100% sure what you are trying to do, but I will give it a crack. If you say
local myTable
you create a variable with value nil. If you say
local myTable = {}
you create an empty table, and set myTable to reference it.
if you say
myTable.gack = “Ack”
you are creating a table element named gack with the value “Ack”
In the loop, if you say
myTable[loopCount] = loopCount
you creating an element whose name is the value of loopCount, and whose value is the value of loopCount. The [] treats the table like an array. If you say
myTable[loopCount].myID = loopCount
when loopCount is 1, you are telling it to set element myID of element 1 of myTable to loopCount. Or myTable.1.myID Since that does not exist, you get an error.
I think what you want is an array(table) of tables. Take a look at this (I put in a simple table printer to help show what is going on.)
---------------------------------------
function printTable( t ) -- Table ref
print("-- "..tostring(t).." --")
for k,v in pairs(t) do
print("ELEMENT "..tostring(k).." VALUE "..tostring(v).." TYPE IS "..type(v))
end
print("---------------------")
end
local myTable = {}
myTable.gack = "Ack"
for loopCount=1,4 do
--myTable[loopCount].myID = loopCount -- nil field value
--myTable[loopCount] = loopCount -- Value = index
-- Table of tables --
myTable[loopCount] = {} -- New tabled referenced by myTable[loopCount]
myTable[loopCount].myID = loopCount
myTable[loopCount].myIDPlusOne = loopCount + 1
end
printTable(myTable)
printTable(myTable[1])
You should see something like this
– table: 02E79E48 –
ELEMENT 1 VALUE table: 02E79E98 TYPE IS table
ELEMENT 2 VALUE table: 02E79E70 TYPE IS table
ELEMENT 3 VALUE table: 02E79EC0 TYPE IS table
ELEMENT 4 VALUE table: 02E79F10 TYPE IS table
ELEMENT gack VALUE Ack TYPE IS string
– table: 02E79E98 –
ELEMENT myIDPlusOne VALUE 2 TYPE IS number
ELEMENT myID VALUE 1 TYPE IS number
[import]uid: 41667 topic_id: 12681 reply_id: 49269[/import]