Hi there,
I’m going crazy here (haha) with the error that I’m getting:
3159: main function has more than 200 local variables
I really need more then 200 variables! How can I do it? [import]uid: 8556 topic_id: 5787 reply_id: 305787[/import]
Hi there,
I’m going crazy here (haha) with the error that I’m getting:
3159: main function has more than 200 local variables
I really need more then 200 variables! How can I do it? [import]uid: 8556 topic_id: 5787 reply_id: 305787[/import]
Ricardo,
I don’t know how to solve this problem (if there’s even a workaround), but I’m curious, are you placing 200+ local variables in one function? Or 200+ in your entire program? I would be shocked if we’re limited to 200 local variables in an entire game… I haven’t counted the variables in my current game, but it’s very likely over that amount, considering all local variables and local functions together!
Hopefully there’s a workaround for this… first time I’ve heard about this error. Perhaps it’s a Lua limitation more than a Corona limitation? 200+ within a single function seems rather heavy IMHO, but I’m sure you have a very specific reason why it must be so.
Brent
[import]uid: 9747 topic_id: 5787 reply_id: 19992[/import]
@IgnisDesign
The error message is not exactly what it looks like. The problem is that functions are considered variables too. I have A LOT of functions at my game.lua file and now I’m working to put it all in different files, but it’s a hard work! [import]uid: 8556 topic_id: 5787 reply_id: 20122[/import]
a workaround is to place the variables in a table
[import]uid: 6459 topic_id: 5787 reply_id: 20217[/import]
do you have code i can look at
carlos [import]uid: 24 topic_id: 5787 reply_id: 20248[/import]
My game.lua file have 3000+ lines. I’m separating some functions into different files.
If I still have problems, I’ll talk to you, Carlos.
Thanks!! [import]uid: 8556 topic_id: 5787 reply_id: 20253[/import]
I had this same problem. The limit seems to be 200 local variables per one single function, and yes you are right, functions count as variables.
I found that consolidating variables into tables works really well if separating becomes too much of a hassle.
Good Luck! [import]uid: 9187 topic_id: 5787 reply_id: 20303[/import]
Ricardo,
you can put as many functions as you like in a table:
local function add(a,b) return a+b end
local function sub(a,b) return a-b end
are 2 local variables, but
local f={["add"]=function(a,b) return a+b end,["sub"]=function(a,b) return a-b end}
is just 1
[import]uid: 6459 topic_id: 5787 reply_id: 20311[/import]
I kept getting too many, 200 etc and found this solution but took a long time to get the functions to work.
You have to call the functions by putting the table name first then a dot.
The table above is called f, therefore to call the function [“add”] from within this table, call:
f.add ((((((not just add)))))) Think - Use a table like you would an external module.
Hope this saves someone some time. [import]uid: 47300 topic_id: 5787 reply_id: 38629[/import]
I’ve just run into this problem as well. Is combining functions into a table the best way around this limit? [import]uid: 1560 topic_id: 5787 reply_id: 96311[/import]
@Dotnaught please see this thread:
http://developer.anscamobile.com/forum/2012/03/20/200-local-variables-limit-problem
Tables are your solution.
[import]uid: 19626 topic_id: 5787 reply_id: 96322[/import]