Local storage working on Firefox but not in other browsers

0 favourites
  • 9 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • I have two layouts (menu/game) and point recording takes place in the game layout. Then, when the game ends, the system opens the menu layout and, if a boolean is true, it register the date, amount of variable points e level, and then shows the score. I am having to restart layout otherwise the score will not update

    This works perfectly on Firefox, but when I tested it on Edge, Safari and Chrome, the score is always zero.

    Could this be due to some incompatibility of local Storage with other browsers? If it works perfectly for Firefox, could there still be an error in the code?

    Thanks

  • Try removing the "trigger once" from everywhere, I have feeling that might cause the issue, although it is unusual that this system works in Firefox but not elsewhere.

    When you call the function, it will trigger once anyway. Make sure not to call the functions too often otherwise yeah, it'll struggle.

    The "sort scores" might end up running every tick, but then could put this under some other event, maybe even a global variable boolean called "IsSorted" that you set to true once the sort has been called, then you can check "IsSorted = false, then call sort function".

    More or less, the "trigger once" works by checking other conditions above this within the same event block (which in your case, there are no extra conditions with the trigger once, meaning, it will trigger, then NEVER trigger again no matter what).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm surprised it's working at all.

    You're not using local storage correctly.

  • Jase00

    Thanks for answering. In fact, I placed these triggers later, trying to force the registration. I know they're wrong, but I was trying everything I could. I have already removed them.

    Now I noticed that the record appears in the score, but instead of appearing at the same moment when opening the menu layout, as happens in Firefox, I have to refresh the game page (or close and open the browser again) and then the points record appears in the second line of the score, with the top line having zeros. My question is: why can't I display the score immediately in other browsers, but only in Firefox and why does it appear on the second line?

  • When LS works on one device/browser and doesn't work on another - this is a clear indication that it's not used correctly.

    Also, saving each element of the array in a separate key is woefully inefficient. You can save or load the entire array as JSON with a single action.

  • When LS works on one device/browser and doesn't work on another - this is a clear indication that it's not used correctly.

    Also, saving each element of the array in a separate key is woefully inefficient. You can save or load the entire array as JSON with a single action.

    I've always done it this way, because I couldn't do it any other way. I've already read about the option of using json, even before you posted I was checking a tutorial that you indicated in another post (https://howtoconstructdemos.com/easily-save-multiple-values-in-local-storage/), but I can't imagine, for example, how to use this type of solution to display the latest 5 registers. Can you talk about it or give me some instructions?

  • I suppose look at local storage as something to use very rarely, like you don't wanna be reading or writing to it as actual game data that you're dealing with, and instead use it strictly to store stuff for future/load on startup.

    Save array AsJson to local storage when saving is needed, then when loading is needed, load into array from your local storage, then do all your data stuff with the array.

  • I've been checking out the demo file that dop2000 shared and I've made changes to my code based on that example. The score is showing the results when it is registered (1st time score panel is open), but when I load the game again, the score is no longer there, just the dates.

    EDITED: I believe I already found the problem and it seems that the score is behaving correctly.

  • I would recommend doing the download on a special starter layout.

    It is better to load the whole array if there is a lot of data.

    I have created a simple example of loading screen and saving array and variable to local storage. This should work on mobiles and all browsers.

    File c3p

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