How do I use LocalStorage to save using a "touched button"?

0 favourites
  • 7 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • Hey! Help me!

    This is the button event:

    How I Storage Locally:

    The problem I found is that it works very well in preview window:

    When I return to Main Menu, it gets back to the first value. All information has been lost.

    Help me, please!

  • Hello! Are you storing the values in local variables? I do like this:

    In the first layou of the game I retrieve the local data I insert into global variables. This way the values are available all the time.

  • A good practice when it comes to local storage is to use it as little as possible. I like to keep everything in a single variable. Then I retrieve and divide the values. From this fomar you avoid being created a lot of enventos. On item exist, on get, etc ...

  • Hi, the bellow example might help, im not sure if it's saving on touch, but it will show you the structure that local saving needs to follow. To modify it for touched object you just replace the trigger that is saving in the example file and save after you made variable updates.

    So your conditional structure should look something like:

    On touched sprite :

    Action 1 add to score 5

    Action 2 localstorage set item "score" value = score

    Where the first "score" is the key name as text and the value is the actual global variable.

    localstorage+level C3 r139 i think, im not sure about the version used, should work with latest C3 though R139 or above.

    However if you are having the ability to tap multiple times to change the score variable, id suggest saving the score, every 1 or 2 seconds that way you avoid spams (think cookie clicker type of game, or tap to cash).

    You can also save every 10 seconds or when user goes back to main menu screen or has intent to close application.

    On the last suggestion the user might lose some data let's say battery dies out or he closes it by mistake, so the saving local has to be done for game progress, this method isn't meant for In App Purchases, for IAP's you need to update a online server store somewhere to make sure transactions are safe and out of the reach of malfunctions.

    The tutorial section on forum should have something about this.

    Hope it helps. Have fun!

  • Hello! Are you storing the values in local variables? I do like this:

    In the first layou of the game I retrieve the local data I insert into global variables. This way the values are available all the time.

    Yes I did that!

    As you can see, I needed to compare some values.

    I have now 4 variables which I need to compare values to know what is the bigger value to store 2 variables.

    Variable "Coins" that colects current coins, so I compare with the "BestCoins" variable to know what is bigger and store in the LocalStorage. So I colect that value to know how many coins I have and the bigger value I keep in "BestCoins" variable.

    I have the same for Diamonds:

    Variable "Diamonds" that colects current coins, so I compare with the "Diamonds" variable to know what is bigger and store in the LocalStorage. So I colect that value to know how many Diamondns I have and the bigger value I keep in "BestDiamonds" variable.

    The problem is that I get that "Best..." variables values and I subtract 100 from Coins to add 5 to Diamonds Touching the Button, but it is not storing that values.

    How can I store this information by Touching the Button?

    It looks like it's working on Math, but it is not storing that values with the commands I did in those events:

    It resets the old value when I use Back button to go to the Main Menu.

    This is my first game on Construct. I'm completely newbie...

    Please Help Me!

  • Well, in any place in the prints I saw you set the value in the local storage.

    -> LocalStorage: Set item "key" to bestCoins

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Well, in any place in the prints I saw you set the value in the local storage.

    -> LocalStorage: Set item "key" to bestCoins

    Hey man! You rock!

    Thank you so much!

    I'll share the solution to help someone:

    Thank you!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)