Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

function at line has more than 60 upvalues
Started by Lourenco Mar 29 2011 10:13 PM

- - - - -
7 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Lourenco

[GLOBAL: userInfoPane.html]
Lourenco
  • Contributor

  • 177 posts
  • Corona SDK

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


[TOPIC: post.html]
#2

jhocking

[GLOBAL: userInfoPane.html]
jhocking
  • Corona Geek

  • 1,223 posts
  • Guests

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.
uid: 12108 topic_id: 8419 reply_id: 30163


[TOPIC: post.html]
#3

kripa1415

[GLOBAL: userInfoPane.html]
kripa1415
  • Enthusiast

  • 42 posts
  • Corona SDK

 
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?


[TOPIC: post.html]
#4

AlanPlantPot

[GLOBAL: userInfoPane.html]
AlanPlantPot
  • Contributor

  • 733 posts
  • Corona SDK

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.



[TOPIC: post.html]
#5

kripa1415

[GLOBAL: userInfoPane.html]
kripa1415
  • Enthusiast

  • 42 posts
  • Corona SDK

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?


[TOPIC: post.html]
#6

AlanPlantPot

[GLOBAL: userInfoPane.html]
AlanPlantPot
  • Contributor

  • 733 posts
  • Corona SDK

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).



[TOPIC: post.html]
#7

eddierush

[GLOBAL: userInfoPane.html]
eddierush
  • Enthusiast

  • 41 posts
  • Corona SDK

Hello Kripa1415,

 

Try placing the singleChar declaration outside the loop

 

local singleChar
for t=1, string.len(dupAnswerStr) do
    singleChar= string.sub(dupAnswerStr, t ,t)
    displayAnswerChars[t] = singleChar
end

 

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



[TOPIC: post.html]
#8

kripa1415

[GLOBAL: userInfoPane.html]
kripa1415
  • Enthusiast

  • 42 posts
  • Corona SDK

thanks @AlanPlantPot , what you said is right.




[topic_controls]
[/topic_controls]