[Solved] Weird and frusrating problem.. Help please!

UPDATE2: I’ve figure out the problem myself. For people who want to know the solution and cause of problem:
Briefly:

  • Lua has a limit per function, each function can only call up to 60 upvalues.
  • Upvalues are variables not stored in the same scope as the function
  • Using a table/array will count as 1 upvalue (i use more tables now [:slight_smile:

For more information:
http://developer.anscamobile.com/forum/2011/04/24/error-more-60-upvalues
http://www.lua.org/pil/6.1.html

UPDATE: I found the problem. It says i have more than 60 upvalues in my function. How do i solve this? Anything below are
I am encountering a weird bug!

Here is the issue:

I have 2 variable, aa and bb that stores Numbers. When i i use print(aa) and print(bb) in that particular function it will cause a runtime error. If i comment either one of them out, it won’t crash. Any ideas what is possibly causing this?

** using both in other functions works perfectly

[lua]–example 1
local function a()
print(aa) – works
end[/lua]

[lua]–example 2
local function a()
print(bb) – works
end[/lua]

[lua]–example 3
local function a() – runtime error, game won’t start, black screen, director error 440
print(aa)
print(bb)
end[/lua]

[lua]–example 4
local function b() – Other functions: works perfectly
print(aa)
print(bb)
end

local function c()
print(aa)
print(bb)
end[/lua]

This is really weird. I don’t know what is causing it. I really want to know the solution. I can print every other variables just fine in function a(). But just not that 2 together which basically stores only Numbers.

** this came into my mind. Is there a local variable limit in corona sdk or director class per .lua file? I have 121 local variables in my game.lua

** i tried creating new variables but i can’t call it in that function anymore. But still able to call in other functions. Is there a limit for functions? [import]uid: 74723 topic_id: 13127 reply_id: 313127[/import]

The variable could be being changed from a decimal into something else somewhere else in your code. Try changing your print lines to:

print(tostring(variable))

and see if that prevents the crash. The console output would also show what the variable has been turned into. For example, if it is a table the output would be something like ‘table: 0x1a1f37b0’, or if you accidentally deleted the variable it would print ‘nil’ [import]uid: 9422 topic_id: 13127 reply_id: 48200[/import]

Thanks for the reply and appreciate your time looking into this. Appreciate it!

I figure out the problem. It has to do with functions upvalues limitations. [import]uid: 74723 topic_id: 13127 reply_id: 48202[/import]