I am getting an error which seems to indicate I have exceeded a limit of 200 local variables. Can anyone confirm this is the case? [import]uid: 7863 topic_id: 4340 reply_id: 304340[/import]
Is this error being displayed the Terminal? If so can you provide the full text?
thanks
Tim [import]uid: 8196 topic_id: 4340 reply_id: 13564[/import]
Yes here it is
Runtime error
error loading module ‘screen2’ from file ‘/Users/macuser/Documents/work/corona development/mygamey68/screen2.lua’:
/Users/macuser/Documents/work/corona development/mygamey68/screen2.lua:3800: function at line 4 has more than 200 local variables
[import]uid: 7863 topic_id: 4340 reply_id: 13568[/import]
Yes, I believe there is a hard coded limit of about 200 local variables in Lua by default. Sorry, you will need to use fewer local variables. (You might try using local tables to group some of your variables together.)
[import]uid: 7563 topic_id: 4340 reply_id: 13606[/import]
Thanks ewing - it is probably a good thing as it has forced me to tidy up my code. I have got it down to 180 so all fine again. [import]uid: 7863 topic_id: 4340 reply_id: 13608[/import]
Just make a Table for Variables.
I was a little put off at first seeing this limit too. Then, I made a table and used my variable names as keys and its just one local variable now.
Instead of:
local var1 = 1
local var2 = 2
local var3 = 3
Do this:
local vars = {}
vars["var1"] = 1
vars["var2"] = 2
vars["var3"] = 3
[import]uid: 6114 topic_id: 4340 reply_id: 13686[/import]
Just IMHO, but any file which has that many variables needs serious refactoring before going any further. While lua is not a traditional OO language (when compared to langs like C++ or C#) it does provide excellent encapsulation in the form of tables. Associated logically elements should always be aggregated into collection objects, whether they are tables, functions, files or simply well-named entities. The proof of the pudding is simply to go back to an untidy program file after 6 weeks of not touching it and see if you can still understand it. Same goes for variable/object naming.
Matt. [import]uid: 8271 topic_id: 4340 reply_id: 13825[/import]
@Alangrus - Thanks, I have done what you suggested - it worked a treat.
@Matt - Yes I totally agree. I think as this was my first Corona game, my code has been a bit of a mess as I have been trying to run before I can walk. I am used to writing classes in AS3 so just need to sort out my coding methodologies in Corona instead of putting all my code in one lua file.
[import]uid: 7863 topic_id: 4340 reply_id: 15817[/import]
I agree… I’ve just rewritten my first app from scratch using an OO approach because deconstructing 3000 lines of code (because I was learning lua and the framework) did not appeal!
Matt [import]uid: 8271 topic_id: 4340 reply_id: 15841[/import]