Localstorage issue

0 favourites
  • 3 posts
  • Hi all,

    I'm getting towards a point where I can publish my game to iOS and Android, but I'm having an issue with localstorage which is making me scratch my head a bit.

    The game functions correctly, and I'm using localstorage to save the hi score and the audio on/off toggle, and now I'm adding in achievements to add a bit of longevity. To drive a few of the achievements, I have to store the total number of enemies killed - so each time an enemy is destroyed, I add 1 to the global variable TotalEnemiesDestroyed. So far, so good. On player destroyed, I'm then setting the localstorage item totalEnemiesDestroyed to the value of the variable TotalEnemiesDestroyed.

    This is working whilst in the game, but if you exit and come back in, the value is wrong, like it's not saving properly or not loading properly on my Start layout.

    So... My question is, are there any limitations with localstorage that I need to know about? Should I try loading everything in my splash screen instead and not progress until it's all loaded? Is there a better way of storing all the data I need to save rather than having separate localstorage items?

    Sorry if I've not explained this very well! Any help or comments would be very much appreciated. I want to finish Swarm so that I can start on some new games thank you in advance!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I don't think there are any limitations at least in how you want it to work for your game. Since the value is wrong when you return to the game, it must mean that you are saving it wrongly. You will need to look at your events again, or post a screenshot or capx here for others to take a look at.

  • As I know, there are no limitations. Make sure that you set your global variable TotalEnemiesDestroyed to localstorage value totalEnemiesDestroyed before you play, so the value goes from where you have left, and not from 0.

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