[Solved] Important Question About Variable

Hello
I need to know if i understood “Variables” well

Know when i am coding, i initialize variable “Score” = 0
User will start the game and his new score in 17
now, which way i should use
Way one: App sets variable “Score”=17 and Local Storage key “Score”=17 and when user uses the app again app will call Local Storage Key and sets the variable “Score” to the local storage value.

or

Way two: when game finishes, app sets variable “Score” = 17 only

MY QUESTION:
in case of using 2nd way, when the user opens the app again, will variable value be 17 or it will be 0 and i have to call Local Storage?

Thanks in advance

2 Likes

You need to use local storage.
The current value of a variable is maintained as long as the app is running. Next time the app will be started, all the initialization will run anew, so the score would start from 0 again.

2 Likes

Even stored variables ? @CBVG

No, not stored variable; those are kept.
This is precisely what this is about.

1 Like

Hi there,

If you use an app variable, it will reset every time the app is closed and re-opened.
If you use a stored variable, it will be stored and recalled even if the app has been closed and re-opened.
Stored variables work just like the Local Storage component, except they are easier to work with!

Have you checked out the docs about variables?

2 Likes

Yes i have checked it but i just wanted to ensure that before i start replacing “Local Storage” by “Stored Variable”

Thanks a lot

1 Like