Lua Tables. nil value

Hi everyone, sorry to bother with this stupid question, but I can’t see what I’m doing wrong. I’ve decided to change a chunk of code already working into a generic part, but the thing gets weird now. Look at this code:

local sequenceData\_Level1 = { { name = "normalRun", start=0, count=1, time=40 }, { name = "goDown", frames={ 1,2,3,4 }, time=40 }, { name = "goLeft", frames={ 5,6,7,8 }, time=40 }, { name = "goRight", frames={ 9,10,11,12 }, time=40 }, { name = "goUp", frames={ 13,14,15,16 }, time=40 }, } ... somevariablereceives = = display.newSprite( theSheet, sequenceData\_Level1 )

This works fine. the variable receives the sprite somewhere inside a function. Now I smartly have change the code to this:

function main() for i=1,#levels do sequenceData[i] = {} sequenceData[i][1] = {} sequenceData[i][2] = {} sequenceData[i][3] = {} sequenceData[i][4] = {} sequenceData[i][5] = {} sequenceData[i][1].name = tonumber(levels[i].child[9].value) ... end --inside the same function somevariablereceives = display.newSprite( theSheet, sequenceData[1] )

Now the code won’t compile anymore when I’m assigning a value to sequenceData[i][1].name with this message:

main.lua:184: attempt to concatenate a nil value

The question is: How can I create dynamically the table sequenceData_Level1 and assign values later?

Thanks,

It is very good when you ask a question and five minutes later found out what was wrong. The problem was that for .name I copied and pasted a tonumber(…) from another variable, when .name return value wasn’t a number but a text  :slight_smile:

So, there is nothing wrong with the table constructor, but the value of tonumber was obviously nil.

I’m glad you solved it.

Rob

It is very good when you ask a question and five minutes later found out what was wrong. The problem was that for .name I copied and pasted a tonumber(…) from another variable, when .name return value wasn’t a number but a text  :slight_smile:

So, there is nothing wrong with the table constructor, but the value of tonumber was obviously nil.

I’m glad you solved it.

Rob