Hi, I’m looking for a possibly simple way to save a number. I have three buttons: A count up button, A count down button, and a button that changes the scene to a different .lua file. When I input a number using the first two buttons, and then change the scene, the number imputed will reset. How can I save the number? Any help is greatly appreciated. [import]uid: 66317 topic_id: 14030 reply_id: 314030[/import]
do you just want to save the number for a single game session ? then you may use a global variable.
you can use it with the global name space
[lua]_G.number = yournumber[/lua]
now u can use the number anywhere in your app by calling it with _G
eg:
[lua]print(_G.number)[/lua] [import]uid: 71210 topic_id: 14030 reply_id: 51684[/import]
Thanks for the reply. I was hoping to be able to save the number until the app is closed. My ‘Number’ is actually my text + 1. Will the _G still apply?
[code]function plus(event)
if event.phase == “ended” then
holScr.text = holScr.text + 1
end
end[code] [import]uid: 66317 topic_id: 14030 reply_id: 51688[/import]
Global variable can hold any value just like local variable. [import]uid: 71210 topic_id: 14030 reply_id: 51693[/import]
I’m sorry, but I’m a noob, and I don’t entirety follow. With this _G, I can cause a .lua file to retain its state even after I reload the app, or change the scene to another .lua file? [import]uid: 66317 topic_id: 14030 reply_id: 51775[/import]