Localstorage not working properly?

0 favourites
  • 8 posts
  • I even put the global variables "HighScorePass" and "Score" in their own event sheet, and included that event sheet in both the level sheet and menu sheet. The menu screen is suppose to show the highscore, but when I try to load from local storage, I get a 0. I tried reading other examples, but somehow, when I test, local storage will not pass unto the global variable. I think local storage is finally working, but it just won't pass into the global variable and isntead resets it to 0.

    The game itself:


    Notice that if you hit refresh, the score resets back to 0?

    Here is the screenshot from the menu event sheet:

    From the level, where the score gets saved. (Scoresaver variable is only to prevent some buttons from being clickable until after the heroes defeat).

    Am I writing it wrong?

    EDIT: The stuff thats crossed out is from my various attempts to get localstorage to work. At first it was saving as words, then finally got numbers showing up in debug mode, then NaN for a while, then numbers, and although local storage appears to save the actual highscorenumber in the debug data, instead of loading into the HighScorePass to display in the text on the menu, it just shows as 0.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I think the problem is in the "On item HighScorePass Get" event.

    You need to remove the Wait.

    Re-enable the line where you assign the LocalStorage.ItemValue to your variable.

    And remove the same line from the On Start of Layout.

    Local Storage events are asynchronous, you need to follow the specific rules when reading/writing to Local Storage.

    See this recent thread for some examples:

  • dop2000 Thank you! It is working now!! There was no way I would have seen that, I probably would have gone a more covulated route in my frustrated state.

    It's quite funny, since the graphics and animations where the easy part for me. I never hit a brick wall or obstacle when making the art. The time it took me to try to solve this bug before posting on here, I would be done with a 3D model of a new enemy character(although the animation set would take an entire day or two). (Which I do by using a 3D program to make the model, then making pseudo-3D sprites from the animations of it.)

    I really should team up with somebody to handle the programming side of stuff for the next game, so I could have more time to work on the graphics. : / Had I done it for this game, I would have 5 more enemy characters, and 3 to 6 more playable heroes, all with finished animation sets.

  • I'm glad it worked

    It's a complete opposite for me - I have many years of programming experience, so all the coding in C2 is a piece of cake. What I struggle with is graphics and visual effects.

  • Thanks again. : D I only do 3D and pseudo-3D sprites now, totally retired from 2D spriting as I'm not as efficient in it. I still do 2D illustrations though.

    Amazing how people can specialize in different things. How easy would it be to implement multiplayer in the type of game I'm working on? Like 2 player same screen local, or via connecting to another android phone so two different people can play simultaneously?

  • dop2000 Is there anyway to save and load images from H5 Local Storage using C2?

  • kentoy

    What's "H5"?

    I haven't tried this, but there are 2 plugins to convert images to/from string (which you can save in local storage):



    Links in those posts are dead, you can download the behaviors from github:


  • dop2000 thank you so much!! you are sweat!...I will try to learn from the links!

    H5 I mean HTML5

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