Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
main function has more than 200 local variables — Gideros Forum

main function has more than 200 local variables

antixantix Member
edited January 2016 in General questions
Suddenly this morning I discovered a new interesting thing about LUA, you can only have 200 local variables :-((

Am I correct in guessing there is no way around this besides grouping vars into tables? or seperating my code into multiple LUA files?

Comments

  • SinisterSoftSinisterSoft Maintainer
    Accepted Answer
    I think it's because it's index via a byte in the bytecode - so no, there is no way around this apart from putting your lesser used variables in a table or not making them local.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • btw I'm not sure if multiple lua files will fix it.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • Thanks SinisterSoft. Well since this is just my game editor that I'm working on I don't think having globals will be the end of the world.
  • After a little experimentation I have discovered that local functions also count as a local variable as far as LUA is concerned, so having 199 local variables and 1 local function will effectively put you at the 200 local variable limit.

    Any function inside a LUA file can have 200 local variables too.
  • piepie Member
    That's interesting. :)
    How do you count them?
    Thank you

    Likes: antix

    +1 -1 (+1 / -0 )Share on Facebook
  • @pie - well I just made a LUA file and manually created created 199 local variables. Adding one more local variable (or function) causes the limit to be reached.

    I don't think there is any way to actually know when you will hit the limit until you do.

    Likes: pie

    +1 -1 (+1 / -0 )Share on Facebook
  • john26john26 Maintainer
    I had this problem too (with Corona as well). The only thing you can do is make some variables global which kind of goes against what we are told about the importance of local variables. Personally I think there is no harm in having local variables in outer scope. I would use local only for variables within functions.

    Likes: antix

    +1 -1 (+1 / -0 )Share on Facebook
  • @john26 - Thanks. Yeah there is no real harm in having a few global variables, I just like everything to be kind of uniform when possible :)

    Hey is Longford the precursor to Gideros?
  • john26john26 Maintainer
    edited January 2016
    No Longford was a program I wrote when Gideros was still closed source (and restricted to Android and iOS targets). The idea was to allow existing Gideros programs to run on new hardware (Longford supports BlackBerry PlayBook, Windows desktop, Windows Store "Metro" and Windows Phone). I initially wrote it because I wanted to port my game to PlayBook but then it grew into something bigger.

    But then Gideros was open sourced and ported to many new targets so Longford is no longer needed really. A lot of Gideros features are absent from Longford as well, so not much point using it these days. The only good thing about it is that the source code is much shorter and simpler than Gideros. And it does support BlackBerry which Gideros still lacks. So perhaps we could add that target to Gideros if there is any interest (and money!)

    Writing Longford gave me lots of the tools needed to prepare the WinRT port of Gideros (knowledge of DirectX and WinRT in particular -- and familiarity with Visual Studio)

    Likes: antix

    +1 -1 (+1 / -0 )Share on Facebook
  • @John26 - Thanks for that :)
  • PACPAC Member
    edited January 2016
Sign In or Register to comment.