function at line has more than 60 upvalues

Am getting the error : function at line 1257 has more than 60 upvalues
Any idea what this is about and how to solve?
[import]uid: 6661 topic_id: 8419 reply_id: 308419[/import]

post your code

ADDITION: Not all of it, just the minimum amount that demonstrates the problem. For starters, post the function that error is on so that we can see what you wrote. [import]uid: 12108 topic_id: 8419 reply_id: 30163[/import]

Whenever i wrote this code

for t=1, string.len(dupAnswerStr) do

            local singleChar= string.sub(dupAnswerStr, t ,t)

            displayAnswerChars[t] = singleChar

end

i am getting this error otherwise it working fine.


error loading module ‘game’ from file 'c:\users\malini\docume~1\corona~1\sandbox

\76\game.lua’:

        c:\users\malini\docume~1\corona~1\sandbox\76\game.lua:1384: function at

line 84 has more than 60 upvalues


can anyone tell me the problem?

I normally find that it means I have missed an “end” somewhere in my code (not necessarily in the function that seems to be causing the problem, it can be anywhere in the Lua file).

Very occasionally it’s because I’ve put an extra “end” somewhere, but 99% of the time it’s due to me missing one out.

In my function whenever i comment this line it working fine

for t=1, string.len(dupAnswerStr) do

            local singleChar= string.sub(dupAnswerStr, t ,t)

            --displayAnswerChars[t] = singleChar

end

 

and i globally declared 

 

local displayAnswerChars = {}

 

please tell me the problem?

In that case you’ve probably triggered the real cause of that error: you have more than 60 upvalues.

Upvalues are variables declared outside of a particular function.

Example:

--myGame.lua local var1 = 0 local var2 = 0 local var3 = 0 local var4 = 0 ... ... ... ... local var 61 = 0 local function Update(event) print(var1) print(var2) print(var3) ...--try to print all 61 variables end

Obviously the … part refers to creating variables from var4 to var61.

This Update function would trigger the “function at line has more than 60 upvalues” error, as it is trying to use more than 60 variables which were created outside the Update function itself. This is a Lua restriction, not a Corona one.

One way around this is to use tables to hold multiple variables. You could even put all of them into a table called vars or something, and then call each one from the table:

--myGame.lua local vars = { var1 = 0, var2 = 0, var3 = 0, var4 = 0, ... ... ... ... var 61 = 0, } local function Update(event) print(vars.var1) print(vars.var2) print(vars.var3) ...--try to print all 61 variables end

This Update function would work (as long as those variables were in fact put into the “vars” table).

Hello Kripa1415,

Try placing the singleChar declaration outside the loop

[lua]

local singleChar

for t=1, string.len(dupAnswerStr) do

    singleChar= string.sub(dupAnswerStr, t ,t)

    displayAnswerChars[t] = singleChar

end

[/lua]

Does that help? I am unable to reproduce your error. Here is a link to a thread very simular to what you are asking:

http://developer.coronalabs.com/node/15616

thanks @AlanPlantPot , what you said is right.

Whenever i wrote this code

for t=1, string.len(dupAnswerStr) do

            local singleChar= string.sub(dupAnswerStr, t ,t)

            displayAnswerChars[t] = singleChar

end

i am getting this error otherwise it working fine.


error loading module ‘game’ from file 'c:\users\malini\docume~1\corona~1\sandbox

\76\game.lua’:

        c:\users\malini\docume~1\corona~1\sandbox\76\game.lua:1384: function at

line 84 has more than 60 upvalues


can anyone tell me the problem?

I normally find that it means I have missed an “end” somewhere in my code (not necessarily in the function that seems to be causing the problem, it can be anywhere in the Lua file).

Very occasionally it’s because I’ve put an extra “end” somewhere, but 99% of the time it’s due to me missing one out.

In my function whenever i comment this line it working fine

for t=1, string.len(dupAnswerStr) do

            local singleChar= string.sub(dupAnswerStr, t ,t)

            --displayAnswerChars[t] = singleChar

end

 

and i globally declared 

 

local displayAnswerChars = {}

 

please tell me the problem?

In that case you’ve probably triggered the real cause of that error: you have more than 60 upvalues.

Upvalues are variables declared outside of a particular function.

Example:

--myGame.lua local var1 = 0 local var2 = 0 local var3 = 0 local var4 = 0 ... ... ... ... local var 61 = 0 local function Update(event) print(var1) print(var2) print(var3) ...--try to print all 61 variables end

Obviously the … part refers to creating variables from var4 to var61.

This Update function would trigger the “function at line has more than 60 upvalues” error, as it is trying to use more than 60 variables which were created outside the Update function itself. This is a Lua restriction, not a Corona one.

One way around this is to use tables to hold multiple variables. You could even put all of them into a table called vars or something, and then call each one from the table:

--myGame.lua local vars = { var1 = 0, var2 = 0, var3 = 0, var4 = 0, ... ... ... ... var 61 = 0, } local function Update(event) print(vars.var1) print(vars.var2) print(vars.var3) ...--try to print all 61 variables end

This Update function would work (as long as those variables were in fact put into the “vars” table).

Hello Kripa1415,

Try placing the singleChar declaration outside the loop

[lua]

local singleChar

for t=1, string.len(dupAnswerStr) do

    singleChar= string.sub(dupAnswerStr, t ,t)

    displayAnswerChars[t] = singleChar

end

[/lua]

Does that help? I am unable to reproduce your error. Here is a link to a thread very simular to what you are asking:

http://developer.coronalabs.com/node/15616

thanks @AlanPlantPot , what you said is right.