Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Understanding variable limits — Gideros Forum

Understanding variable limits

PACPAC Member
edited January 2016 in General questions
Hi everyone at Gideros.
I started learning lua and gideros about a month ago with the goal of porting a crossword puzzle game that I wrote years ago in Blitz3D basic. Basic is the only language that I know.
The main game was working until I started to add menu and level options.
Now some variables are being read as nil. All are on the same file. I have tried using all local variables and functions, then all global, and then a mix.
I'm storing the level's data (letters, clues, grid_x, grid_y) in arrays {[ ]} and
{[ ] [ ]}.

I have pre-defined all variables and tried this 2 different ways. First at the top of the file and then in > function GameInit(), read at the start.
But now as the game has expanded some global variables are reading as (a nil value). The variables reading nil keep changing as I tweek the code.

Have I exceded limits?
antix found a limit of 200 locals on another post.
What about global? The global variables are also reading nil .
If an array { } holds 200 indexes, is this still one variable?

Again, lua is new to me and so I'm still trying to understand concepts.
Don't know what direction to go next ... thanks for reading :-)

Comments

  • piepie Member
    edited January 2016
    @PAC if my understanding of lua is correct one array is just a variable of type "table", so it should count as 1, no matter how many indices you have inside it.

    Use local everytime you can :)

    However I believe that your problem is somewhere else, if you reach the limit you get a specific error message
    main function has more than 200 local variables
    Maybe there is just some delay reading all the stuff, or a wrong file loading order (right click on a lua file in project tree and check code dependencies/call order)

    you could try ZeroBrane Studio to debug your project, there are many posts about it and I think at least one tutorial on how to set it up
  • Are you able to post any code so we can maybe see whats happening?
  • PACPAC Member
    I ran my code through ZeroBrane Studio (thanks for the lead), this will be helpful in the future. I was able to get my game working but ZeroBrane crashes on my failed ones without a report.
    I noticed that ZeroBrane calls an instance of a Class object 'global' even though my code defines it 'local'. I tested this with "Jumping Balls" also.
    And it nags about defined 'locals' at the top of a global function. Probably just small stuff ...
    Thanks for the suggestions.
  • PACPAC Member
    Found the problem crashing the game. This might be of some help.
    Lua starts an array index at [1], not [0]. I initially defined this one array from 0-14 even though I planned on using 1-13. Well, getting close to finishing the coding for this part of the project and doing some clean-up, I tightened the code to 1-13 while adding new code elsewhere, starting endless crashing. Once the array got defined from 0-14 is was fine.
  • piepie Member
    @PAC I'm glad you found it.

    keep in mind that (for your sake :P ) it's usually better to start arrays from 1 because "it is customary in Lua to start arrays with index 1. The Lua libraries adhere to this convention; so, if your arrays also start with 1, you will be able to use their functions directly".
    http://www.lua.org/pil/11.1.html

    The first example that comes to my mind: using ipairs will start from 1, not 0 or negative numbers.
    :)
Sign In or Register to comment.