I would like to know how to manage variables in corona throughout different scenes. In my game score variable is in every scene what i want to know is how to continuously add the score per scene, because every time the scene changes the score automatically becomes zero.
You can use a separate file. Example:
mydata.lua
With a table:
local M = {}
return M
-- Then in your game.lua you can simply require it:
local mydata = require( "mydata" )
and use for example a score:
mydata.score = 0
In your highscore.lua or whatever you can call it easy pzy:
local mydata = require( "mydata" )
and now you can use mydata.score saved value
I hope Scenes are no more used . You can try the composer which is very effective and efficient .
http://docs.coronalabs.com/api/library/composer/index.html
It has two functions setVariable() and getVariable(). Using these functions you can pass your score from one scene to other .
since using of global variable may lead to memory leak, its better not use the global variabes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With