In a board game, I have a scene where the player can click on the button for the level he wants to play. This enters the number value of the level in a local variable. This is sent to another Module handling the level about to be played. With the number value of the level passed onto it, data about the level is retrieved from another Module. Thus the next scene is created for the proper level. Very simple and it works well except for one detail that I do not understand:
- the number of the level is retrieved from the params from the last scene. It works. No problem there. I used print() to check it.
local levelId = options.levelId
- levelId is given for the creation of levelData. There is nothing wrong with that either.
local levelData = levelsParams.getLevelData(levelId)
Here is the problem. When used as above, I get:
Corona Simulator Runtime error
Attempt to index local ‘levelData’ (a nil value)
But if I just add “+ 0”, it works:
local levelId = options.levelId + 0
local levelData = levelsParams.getLevelData(levelId)
Are there values similar to Int or String in Lua? Or something else?
I would appreciate any explanation on this.