Inserting records into a table ?

This always confuses me with Lua.

I have a table like this - 

[lua]

local winningsTable = {

{ rowID = 0, amountWon = 0 }

}

[/lua]

Can happily set values using winningsTable[“rowID”] = 10.

But how do add another record ?

Now if I know how many I need to add I can do this when setting up the table but if I don’t know how many, how do I add them. I know there is a table insert command but that doesn’t seem to work.

Dave

Can happily set values using winningsTable[“rowID”] = 10.

 
If you do that you’ll end up with is a table like this (I don’t think that’s what you want):

winningtable = {

    [1] = {rowID = 0, amountWon = 0},

    [“rowID”] = 10

}

If you want to set the value of “rowID” in your first row you should use

winningtable[1][“rowID”] = 10

To add a second row to your table you simply call 

winningtable[#winningtable + 1] = {rowID = 0, amountWon = 0}

BTW.

If rowID above is just to keep an index of that particular row you don’t need it since the index is implicit in the table.

row 1 = winningtable[1]

row 2 = winningtable[2]

etc.

Cheers, it was this I needed -

winningtable[#winningtable + 1] = {rowID = 0, amountWon = 0}

I just couldn’t work it out, I was trying winningsTable[2][“rowID”] = without doing the above first.

Yeah rowID isn’t actually the row in the array it is referencing a rowID from a SQLite Table, so I know which rows need updating.

Dave

Can happily set values using winningsTable[“rowID”] = 10.

 
If you do that you’ll end up with is a table like this (I don’t think that’s what you want):

winningtable = {

    [1] = {rowID = 0, amountWon = 0},

    [“rowID”] = 10

}

If you want to set the value of “rowID” in your first row you should use

winningtable[1][“rowID”] = 10

To add a second row to your table you simply call 

winningtable[#winningtable + 1] = {rowID = 0, amountWon = 0}

BTW.

If rowID above is just to keep an index of that particular row you don’t need it since the index is implicit in the table.

row 1 = winningtable[1]

row 2 = winningtable[2]

etc.

Cheers, it was this I needed -

winningtable[#winningtable + 1] = {rowID = 0, amountWon = 0}

I just couldn’t work it out, I was trying winningsTable[2][“rowID”] = without doing the above first.

Yeah rowID isn’t actually the row in the array it is referencing a rowID from a SQLite Table, so I know which rows need updating.

Dave