I made a table to avoid more than 60 upvalues in my reset function

Here is me making the table outside of the function. (I commented out my previous work that worked fine until I needed to make a table). I think the problem is that box1num and the others are no longer being defined as locals? But If I remember correctly, even if I added local within the brackets, I wasn’t able to get it to function without error "unexpected symbol near ‘local’ ".

Currently the error message is the following: “attempt to index field ‘box1num’ (a nil value)” in my reset function.

Code outside the reset function:

[lua]local boxTable = {box1num, box2num, box3num}

–local box1num 

–local box2num

–local box3num

[/lua]

*edited*

[lua]

box1num= native.newTextField (x, y, display.contentWidth/10, display.contentHeight/28, function )

box1num:setReferencePoint (display.CenterReferencePoint)

box1num.x = display.contentWidth/1.7

box1num.y = display.contentHeight/3.6[/lua]

Within the reset function:

[lua]

        boxTable.box1num.text = 0

        boxTable.box2num.text = 0

        boxTable.box3num.text = 0

[/lua]

Thanks for any help, any ideas/thoughts are much appreciated!

In your example:

local boxTable = {box1num, box2num, box3num}

You are creating a table with keys called “box1num”, “box2num” and “box3num” but they have no value (i.e. they are all set to “nil” by default).

Then in your reset function you are trying to access their “text” property…but they don’t have any properties because they are nil objects.

Unless you’ve already done this and missed it out of your post, you need to create each item at some point (I presume they are display.newText objects):

boxTable.box1num = display.newText("hello world", 0, 0, font, 20)

To sort of further elaborate on what Alan is saying, this…

[lua]local boxTable = { 9, 12, 4 }[/lua]

is the same as this…

[lua]local boxTable = {}

boxTable[1] = 9

boxTable[2] = 12

boxTable[3] = 4[/lua]

Numbers are implied by their position in the table. 

[lua]local boxTable = { “this is entry 1”, “this is entry 2”, “this is entry 3”, “and so on” }[/lua]

If you specify a name as you did with box1num that has no quotes around it, Lua thinks you have just typed a variable. So you would need to define what box1num is prior to adding it anywhere. Otherwise, it’s ‘nil’.

Thanks for your responses! I did forget to mention that I did define them after making the table, sorry about that. I just edited my main post as well.  Here’s one for example:

[lua]

box1num= native.newTextField (x, y, display.contentWidth/10, display.contentHeight/28, function )

box1num:setReferencePoint (display.CenterReferencePoint)

box1num.x = display.contentWidth/1.7

box1num.y = display.contentHeight/3.6[/lua]

So I guess I wrongfully assumed that making a local table and placing box1num (and others) into this table will also make box1num a local object so that I wouldn’t need to worry about the 60 upvalue limit for my reset function.

So the big question: Is there a way to have table values to be entered into the table as a local object? Or should I go through my code for every “box1num” and change it to “boxTable.box1num”? 

Here is the original post I read that I thought I was doing right by creating a table. But now that I’m reading it again, it seems for my situation I would have to define them in my reset function? So I’m guessing I won’t be able to use their method.

http://forums.coronalabs.com/topic/15460-runtime-error-function-has-more-than-60-upvalues/

Thanks again for the help!

In your example:

local boxTable = {box1num, box2num, box3num}

You are creating a table with keys called “box1num”, “box2num” and “box3num” but they have no value (i.e. they are all set to “nil” by default).

Then in your reset function you are trying to access their “text” property…but they don’t have any properties because they are nil objects.

Unless you’ve already done this and missed it out of your post, you need to create each item at some point (I presume they are display.newText objects):

boxTable.box1num = display.newText("hello world", 0, 0, font, 20)

To sort of further elaborate on what Alan is saying, this…

[lua]local boxTable = { 9, 12, 4 }[/lua]

is the same as this…

[lua]local boxTable = {}

boxTable[1] = 9

boxTable[2] = 12

boxTable[3] = 4[/lua]

Numbers are implied by their position in the table. 

[lua]local boxTable = { “this is entry 1”, “this is entry 2”, “this is entry 3”, “and so on” }[/lua]

If you specify a name as you did with box1num that has no quotes around it, Lua thinks you have just typed a variable. So you would need to define what box1num is prior to adding it anywhere. Otherwise, it’s ‘nil’.

Thanks for your responses! I did forget to mention that I did define them after making the table, sorry about that. I just edited my main post as well.  Here’s one for example:

[lua]

box1num= native.newTextField (x, y, display.contentWidth/10, display.contentHeight/28, function )

box1num:setReferencePoint (display.CenterReferencePoint)

box1num.x = display.contentWidth/1.7

box1num.y = display.contentHeight/3.6[/lua]

So I guess I wrongfully assumed that making a local table and placing box1num (and others) into this table will also make box1num a local object so that I wouldn’t need to worry about the 60 upvalue limit for my reset function.

So the big question: Is there a way to have table values to be entered into the table as a local object? Or should I go through my code for every “box1num” and change it to “boxTable.box1num”? 

Here is the original post I read that I thought I was doing right by creating a table. But now that I’m reading it again, it seems for my situation I would have to define them in my reset function? So I’m guessing I won’t be able to use their method.

http://forums.coronalabs.com/topic/15460-runtime-error-function-has-more-than-60-upvalues/

Thanks again for the help!