LocalStorage takes too long to save

0 favourites
  • 14 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • Hi. I'm a rather new user of Construct, and only recently even discovered localstorage. I'm making a simple game that requires to save some statistics, including high scores after every time the user plays.

    When trying the debug feature, I can see the stats do save to localstorage, but they take some time, sometimes up to a minute, which tells me that at least the saving part of my code works. However, since this is for a phone game, users won't wait a whole minute for the game to save before closing the app.

    I wanted to know if localstorage usually takes this long to save data, or if you've had similar experiences with this.

    Thank you!

  • Can you upload your project or screenshot?

    It will help us a lot to imagine your problem :)

  • Thanks for your reply, Maverick.

    The following screenshots are specifically for the lifetime score variable, which simply is the sum of all the scores the player has ever had ever.

    I started with a specific Event Sheet for the saving, which I included in the playing level layouts, as shown below.

    As I at first thought it was outright not saving anything, I also added it specifically in the levels, when the game over menu is displayed, right after the score has been added to the lifetime score, as shown below.

    As I mentioned before, all of the global variables work and the localstorage does ultimately save, but it takes too long doing so.

  • It seems I missed the first image. I can't edit my post so I will add it here.

  • could it be you're just setting the local storage item too many times? It doesn't seem like it's really needed to save it on every tick, which actually happens twice lives are below zero.

    I would try and set it, only when the score actually changes, like in the touch event.

    On my youtube channel there are several games that set a best score, and they never do it on tick or just when checking a variable. It's always triggered... for example the 2048 game tutorial, but there are others as well

    youtube.com/channel/UCZ6QjvqEs9dR2miRnfFqIpQ

    hope that helps

  • Thanks for your answer, Bartalluyn.

    The every tick saving was actually a desperate attempt from me to make the game save faster to localstorage, but it was unsuccessful. I just did a test in which I toggled that disabled, and left the saving to trigger when the user lost, meaning the game over menu is displayed (which can be seen here:

    It still takes a long while to save.

    It's interesting because the global variables do change immediately, so this is definitely a problem regarding either when the saving is triggered or simply that the saving takes that long by default (which I hope is not the case).

  • lp96, as bartalluyn mentioned, you should put the action save to Local Storage in the triggered once condition.

  • I added the triggered once condition as a sub-event to the game over events like this:

    But nothing changes. It saves, but unfortunately still takes a long time.

  • You've not shown any events that indicate how long the action took. So you could just be measuring this wrong and being misled by whatever you're looking at.

    Either use the 'Wait for previous actions to complete' system action, or the 'On item set' trigger, to find out when the write to storage completed. Even on a slow system it should complete within a couple of seconds, and most of the time it should be almost instant.

  • I'm using the debugging preview to check on the time. I go to localstorage object and check on the keys, and there I see how long it takes to save. Is this a reliable method to do so?

  • Well, not really, the events I mentioned are the best way to check timings. Maybe there's a problem with the debugger where it doesn't show updated information quickly or something.

  • Alright, I did the Wait for Previous Actions to Complete while also keeping an eye on the debugger. It did perform the action a little faster than what it took the debugger to display the new saved data, but it's still taking around 30 seconds or something like that:(

  • Update: The high score works perfectly. It saves instantly to the localstorage. It is the lifetime score variable the one I'm having problems with, which is basically the sum of all the scores the player has ever had. Now I'm even starting to wonder if this is actually something that can be done, although I don't see why it shouldn't.

    I even tried to do exactly the same process with lifetime score than the one I use with high score, but so far, it still is taking a long time to save the lifetime score:(

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Please post your project, providing exact steps to reproduce the issue you are encountering.

    This will make things easier to check out.

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