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
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
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
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.
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.
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.