Hi !
I’m creating a game and on the playGame.lua I create a score (which is in reality a timer).
I would like to display this score in the GameOver.lua, is this possible ? And how ?
Thank you for your answer ! (if you want me to be more precise, ask me questions)
JonPM
April 19, 2016, 6:44pm
2
There are a few different ways to handle this, but using composer.setVariable and composer.getVariable is one of them
Hi,
Do you want to save the variable so it’d also be accessible when an app is closed and re-opend?
Try this: https://coronalabs.com/blog/2014/10/14/tutorial-saving-and-loading-lua-tables-with-json/
If you don’t meed to get the number back every time you open the app, you could just use a global variable instead of a local variable.
I hope this helps
If you want to add/retrieve variables without using globals, and if you want to save values between application runs, I’ll give a shameless plug for my plugin GBC Data Cabinet .
rob
April 20, 2016, 8:34pm
5
Please don’t use globals. There are so many options to avoid it.
Use a simple data table that you require in each module: http://coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/
@JonPM mentioned using Composer’s key-value store .setVariable(), .getVariable()
Composer scenes can pass parameters that are available in scene:create() and scene:show():
composer.gotoScene( "newscene", { time = 500, effect="crossFade", params = { key1=value1, key=value2, key3=value3 } )
and in “newscene”'s scene:create() and scene:show()
local params = event.params local key1 = params.key1 print( key1 ) -- prints value 1
@schizoid2K ’s data cabinet works for many.
Rob
You can give my module a go if you’d like. Very easy to use.
http://sh.st/ITwPy
JonPM
April 19, 2016, 6:44pm
9
There are a few different ways to handle this, but using composer.setVariable and composer.getVariable is one of them
Hi,
Do you want to save the variable so it’d also be accessible when an app is closed and re-opend?
Try this: https://coronalabs.com/blog/2014/10/14/tutorial-saving-and-loading-lua-tables-with-json/
If you don’t meed to get the number back every time you open the app, you could just use a global variable instead of a local variable.
I hope this helps
If you want to add/retrieve variables without using globals, and if you want to save values between application runs, I’ll give a shameless plug for my plugin GBC Data Cabinet .
rob
April 20, 2016, 8:34pm
12
Please don’t use globals. There are so many options to avoid it.
Use a simple data table that you require in each module: http://coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/
@JonPM mentioned using Composer’s key-value store .setVariable(), .getVariable()
Composer scenes can pass parameters that are available in scene:create() and scene:show():
composer.gotoScene( "newscene", { time = 500, effect="crossFade", params = { key1=value1, key=value2, key3=value3 } )
and in “newscene”'s scene:create() and scene:show()
local params = event.params local key1 = params.key1 print( key1 ) -- prints value 1
@schizoid2K ’s data cabinet works for many.
Rob
You can give my module a go if you’d like. Very easy to use.
http://sh.st/ITwPy