Lua local ( 200 ) limit and how to remove { } values?

I read about the limit of 200 local variables so I realized I was getting close to the limit. But is the limit a “limit” to each lua file or the entire app?

Also, I started grouping my variables in each scene like below but I’m a bit confused about the removing?

  
local uiStuff = {}  
local sounds = {}  
function scene:createScene( event )  
local group = self.view  
 -- background  
 uiStuff[1] = newRect(group,0, 0, 320, 480 )  
 -- navbar  
 uiStuff[2] = newRect(group,0, 20, 320, 44 )  
 -- etc.......  
end  
  
-- fast forward......... :)  
function scene:destroyScene( event )  
-- this gives an error in the console.  
 uiStuff[i]:removeSelf()  
 uiStuff[i] = nil   
  
end  

Once every 5-10 searches I get this error, it does not crash my app but the strange thing is I don’t even call any setTextColor() on my text objects?

Runtime error  
 ?:0: attempt to call method 'setTextColor' (a nil value)  
stack traceback:  
 [C]: in function 'setTextColor'  
 ?: in function <?:3>  
 ?: in function <?:229>  

Last question…

where do I call storyboard.purgeScene() and storyboard.removeScene( )? [import]uid: 65840 topic_id: 35863 reply_id: 335863[/import]

The limit is per lua file. That’s why people tend to use the “modules” concept.

This sample main.lua “requires” in a seperate lua file (helpers.lua) and calls a function from it.

local helpers = require("helpers") helpers.doThis()

Here’s how helpers.lua might look:

[code]local M = {}

function M.doThis()
print(“hi there!”)
end

return M[/code]

You can design modules in different ways, but this one basically is a table of functions. At the end of the file you “return” the table, which means that any other lua file looking at it will see “M” (so “helpers” == “M”) You can continue this process indefinitely, with files requiring files requiring files…

Another solution people use is tables.

[code]local this – variable 1/200
local that – variable 2/200

that = {} – now that is a table
that.something = 2 – this is not a new variable against the limit, because it’s still part of “that”[/code]
[import]uid: 41884 topic_id: 35863 reply_id: 142634[/import]

I have sen that module/class thing but never really tried it yet. Good to know with the 200 locals.
[import]uid: 65840 topic_id: 35863 reply_id: 142716[/import]

The limit is per lua file. That’s why people tend to use the “modules” concept.

This sample main.lua “requires” in a seperate lua file (helpers.lua) and calls a function from it.

local helpers = require("helpers") helpers.doThis()

Here’s how helpers.lua might look:

[code]local M = {}

function M.doThis()
print(“hi there!”)
end

return M[/code]

You can design modules in different ways, but this one basically is a table of functions. At the end of the file you “return” the table, which means that any other lua file looking at it will see “M” (so “helpers” == “M”) You can continue this process indefinitely, with files requiring files requiring files…

Another solution people use is tables.

[code]local this – variable 1/200
local that – variable 2/200

that = {} – now that is a table
that.something = 2 – this is not a new variable against the limit, because it’s still part of “that”[/code]
[import]uid: 41884 topic_id: 35863 reply_id: 142634[/import]

I have sen that module/class thing but never really tried it yet. Good to know with the 200 locals.
[import]uid: 65840 topic_id: 35863 reply_id: 142716[/import]

I have sen that module/class thing but never really tried it yet. Good to know with the 200 locals.
[import]uid: 65840 topic_id: 35863 reply_id: 142716[/import]

I have sen that module/class thing but never really tried it yet. Good to know with the 200 locals.
[import]uid: 65840 topic_id: 35863 reply_id: 142716[/import]