I seam to have not used locals at all, just so I can call them from other functions. Is that a bad habit?
![]() |
|
Label: corona android iphone ipad building error inmobi problem display screen View image tableView failed object physics touch button game lua config event listener |
How important are local variables?
its bad for memory heavy games(lots of objects)
So what's the problem with local variables? You can call them from other functions just as easily. The only situation I can think of where you can't access a local variable is when you create it inside a function/module and then try to access it outside that function/module. But creating a global inside a function is a very bad idea.
By using only globals you actually produce spaghetti code and make it harder for yourself to maintain the program as it grows in size. The more modular and independent pieces of your code are, the better.
I will attempt to use locals more then :)
Local variables make your code faster, generally.
Here's a great post on locals as well as some good comments too.

热门文章
GameCenter LeaderBoards and Achievements Enabled Through OpenFeint
send message and call to a person
Forum: Report Spam + PM
[INSTALL_PARSE_FAILED_NO_CERTIFICATES]
[SOLVED] Director ERROR: Failed to execute new( params ) function on 'screen1'
Too many (200) local variables
Corona SVG Level Builder released. Drag and drop physics level editor with Inkscape and SVG.
Small bug in Collectible Items example
Can't make removeSelf() delayed
Pivot Joints and apparent elasticity
send message and call to a person
Forum: Report Spam + PM
[INSTALL_PARSE_FAILED_NO_CERTIFICATES]
[SOLVED] Director ERROR: Failed to execute new( params ) function on 'screen1'
Too many (200) local variables
Corona SVG Level Builder released. Drag and drop physics level editor with Inkscape and SVG.
Small bug in Collectible Items example
Can't make removeSelf() delayed
Pivot Joints and apparent elasticity
corona forums © 2003-2011