Function has more than 60 upvalues error

Hi guys,

I’ve been getting an error and can’t seem to resolve it. This is the error: “function at line 150 has more than 60 upvalues”. I’m basically trying to pause all the timers and transitions to make room for the pause menu screen. Am I missing something? I’ve never encoutered an error like this before :confused:

This is the code that it is yelling at:

 -- ------------------------------------------------------------------------------- -- Pause function function pauseToMenu(event) composer.gotoScene("menu") pauseMenuGroup.alpha = 0 display.remove(pauseMenuGroup) end function menuToPlay(event) transition.resume(coinTransition) transition.resume(goldenCoinTransition) transition.resume(billTransition) timer.resume(spawnCoinTimer) timer.resume(spawnBillTimer) timer.resume(spawnGoldenCoinTimer) timer.resume(speedTimer) pauseMenuGroup.alpha = 0 pauseToggled = false end function tapPause(event) bestScoreTxt.text = "Your highest score on easy is " .. settings.highestScoreLevel1 .. ", keep it up!" pauseCoinTxt.text = "You've earned " .. bonusTrack .. " coins during this game so far!" if pauseToggled == true then transition.resume(coinTransition) transition.resume(goldenCoinTransition) transition.resume(billTransition) timer.resume(spawnCoinTimer) timer.resume(spawnBillTimer) timer.resume(spawnGoldenCoinTimer) timer.resume(speedTimer) pauseMenuGroup.alpha = 0 pauseToggled = false else loadsave.saveTable(settings, "settingsGame.json", system.DocumentsDirectory) transition.pause() timer.pause(spawnCoinTimer) timer.pause(spawnBillTimer) timer.pause(spawnGoldenCoinTimer) timer.pause(speedTimer) pauseMenuGroup.alpha = 1 pauseToggled = true end pauseHomeBtnRect:addEventListener("tap", pauseToMenu) pausePlayBtnRect:addEventListener("tap", menuToPlay) end

Kind regards

bram

From this thread:

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

Also, it’s common to get this error if you accidentally miss an “end” when declaring a function/if statement/loop.  

This is because the function/if statement/loop extends further than you intended, and so contains other functions variables etc.

From this thread:

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

Also, it’s common to get this error if you accidentally miss an “end” when declaring a function/if statement/loop.  

This is because the function/if statement/loop extends further than you intended, and so contains other functions variables etc.