Can you max out variables in lua code?

I’m building an app with Photoshop and utilizing the KWIK plug-in.  I have a page divided into 8 non-touching areas, each area has 8 layers (illustrations). A total of 64 layers. (Hair, L eye, R eye, L ear, nose, R ear, mouth, body) Each layer is turned into a button and then Hide/Show actions to navigate through the different face pictures. Everything was working until I reached the mouth layers. Two of the mouth layers were turned into buttons O.K, but the simulator now goes black once I proceed with turning another of the other six layers into buttons.

 

Corona Terminal - simulator states:

error loading module ‘page_4’ from file ’

page_4.lua:1166: function at line 13 has more than 200 local variables

 

Line 13 in page_4.lua says: local drawScreen = function ()

 

Any ideas what is going on here? Thank you.

Yes, as you’ve found the maximum is 200 local variables

This is easily solved by doing something like:

[lua]

local v = {}

local gfx = {}

v.speed = 12

v.score = 0

v.highScore = 58

v.board = {33,135,331,41,1,16,1}

gfx.bg = display.newImageRect(“bg.jpg”,480,320)

[/lua]

This will only use 2 local variables but you can store thousands of variables or objects within the tables.

Thank you, Nick.

For some clarification here… Any animation, action, hide and show, piece of art counts as a singe variable? Prior to creating anything, I should place all 64 layers into a table?

Anything that you define as local yes, whether it be a value, transition, timer, object etc. So I put all my timers, transitions etc into their own table as I did above with the variables and graphics objects.

If you have 64 objects making up your face, you should definitely have these in their own table. Is each of your ‘layers’ getting their own touch listener?

That’s correct.  Each “layer” when touched will hide. And the next image (button) appears…, etc.

That’s pretty much it… no transitions, values or timers in operation. I do have audio “pops” that sound for each layer.

Yes, as you’ve found the maximum is 200 local variables

This is easily solved by doing something like:

[lua]

local v = {}

local gfx = {}

v.speed = 12

v.score = 0

v.highScore = 58

v.board = {33,135,331,41,1,16,1}

gfx.bg = display.newImageRect(“bg.jpg”,480,320)

[/lua]

This will only use 2 local variables but you can store thousands of variables or objects within the tables.

Thank you, Nick.

For some clarification here… Any animation, action, hide and show, piece of art counts as a singe variable? Prior to creating anything, I should place all 64 layers into a table?

Anything that you define as local yes, whether it be a value, transition, timer, object etc. So I put all my timers, transitions etc into their own table as I did above with the variables and graphics objects.

If you have 64 objects making up your face, you should definitely have these in their own table. Is each of your ‘layers’ getting their own touch listener?

That’s correct.  Each “layer” when touched will hide. And the next image (button) appears…, etc.

That’s pretty much it… no transitions, values or timers in operation. I do have audio “pops” that sound for each layer.