your original error has nothing to do with the “size” of the function, or how many lines it has – fe, a single unwieldy line could be crafted that produces that error. what it does mean is that your function references too many variables declared in more-outer scopes - which strongly suggests that you are long overdue for a refactoring.
@davebollinger is correct.
I think the limit for locals is 200-ish in Lua.
Trick: If you ever what to know how many locals are in scope at a particular line of code in your file, function, etc. Do this:
-
Add this code in main.lua (near top)
function _G.countLocals( level ) level = level or 2 local i = 1 while(debug.getlocal(level,i) ~= nil ) do local name,value = debug.getlocal(level,i) i = i + 1 end print(“Found: " … tostring( i ) … " Locals” ) return i end
Now, anywhere you want to check you can type:
\_G.countLocals() -- Prints # locals in scope at this point in your code.
200 locals per module, 60 upvalues per closure, hard limits
As promised, two (very basic) starters, one with and one without SSK2:
https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/03/starters.zip
For better starters, see my marketplace content:
A great starter with pausing, resuming, etc. is: https://marketplace.coronalabs.com/asset/balloon-pop-game-templates
If you only have PayPal, you can go here: https://sellfy.com/roaminggamer
Thanks a lot @roaminggamer! I think Dave is right, I have a lot of variables referenced. Thanks a lot for your help!
Rather than having loads of variables, you can put related ones in tables.
[lua]
local playerScore = 0
local playerHighScore = 300
local playerDead = false
local playerPositions = {0, 0.5, 1.5, 3}
[/lua]
can become:
[lua]
local player = {score = 0, highScore = 300, dead = false, positions = {0, 0.5, 1, 1.5}}
[/lua]
Immediately saving three local variables.
usually that message means you are missing an “end” somehwere, although things can get too big but I’ve never encountered it. It was always a missing end, which means the function gets huge covering most of your code from that point on.
should probably look like this:
if var1 == 1 then
var2.x=200
doFunction()
–blaa blaa blaa
end)
end
To test it out, I added a line to the function:
print("hey")
and it works.
I have checked and I am not missing any ends
se my corrected code above, it has one end missing, the function also need an end with a “)” after
wait…why would you need to add two ends?
By the way, this was my full error:
error loading module 'scene1' from file 'C:\Users\Buscey\Documents\Corona Projects\TheGame\scene1.lua': 17:01:01.270 C:\Users\Busceyt\Documents\Corona Projects\TheGame\scene1.lua:1169: function at line 971 has more than 60 upvalues 17:01:01.270 stack traceback: 17:01:01.270 [C]: in function 'error' 17:01:01.270 ?: in function 'gotoScene' 17:01:01.270 C:\Users\Buscey\Documents\Corona Projects\TheGame\home.lua:16: in function '?' 17:01:01.270 ?: in function \<?:190\>
my bad, thought you did a function directly there, but see now you call an external one.
your code is good and you are likely missing an end somewhere else in your code
the case with this error is the error message wont recognize it and tell you where it is since the code just tries to close the function further down…generating the max 60 upvalues error once that limit is reached.
you should probably google “lua max 60 upvalues error” to understand what this means.
but i bet its a missing “end” 
you need to step through the code the hard way
If I was missing an end it would look like this:
But right now it looks like this:
Should I just make another gameloop or something?
EDIT: Excuse my bad hand writing
well then you have more than 60 upvalues in the main code or in a function.
its a lua limitation and while you can easily fix it, you first need to find out where there problem is.
each function as well as the main document (being a function in itself) can have max 60 upvalues, which translates to max 60 variables if i recall right.
find the place it happens and divide the code up into at least 2 functions and problem solved.
your handwriting is just like everyones when writing with a mouse 
which IDE are you using btw?
Haha yah, I actually use touchpad; not a mouse kind of guy,
The IDE is Notepad++
If for example:
--Old Gameloop local function Gameloop() if var1==1 then var2.text="Yoooooo" var3.x=150 doFuntion() print("updated") end Runtime:addEventListener("enterFrame",Gameloop)
And I change it to this:
--New Gameloop local function updateGame() var2.text="Yoooooo" var3.x=150 doFuntion() print("updated") end local function Gameloop() if var1==1 then updateGame() end Runtime:addEventListener("enterFrame",Gameloop)
Would that reduce the number of upvalues?
Tip: Don’t use a game loop at all.
Instead, spread your logic out into small event driven functions.
None of my games use a game loop.
the first part is missing and end to close the gameloop function.
both the IF statement and the GAMELOOP function need one END each, and you code only has a single end.
told ya its a missing end =P