How do I use the LocalStorage Plugin?

1 favourites
From the Asset Store
The I18N (Translation) is a Construct plugin created to translate text in game.
  • I seem to have a problem. I have a fairly simple localStorage high score function that works fun when I run the layout from C2, but when I exported it and uploaded it to chromestore and scirra arcade, it just returns 0, any ideas on how i could fix this? thanks.

    Hi,

    it would help us a lot if you could provide a capx example

    Otherwise it's nearly impossible to say what the issue causes.

    Regards

    Andy

  • can't give links, but will a picture of the relevant code do?

    it works fine when I test it, just not when I upload it.

  • can't give links, but will a picture of the relevant code do?

    it works fine when I test it, just not when I upload it.

    Hi,

    that's fine. You made a simple mistake.

    See following part

    Score < HighScore (fine)

    HighScore < 0 (this is only true if the score is less than 0 --> Set it to HighScore > 0).

    That's why your HighScore will never be saved.

    Regards

    Andy

  • I wish that were the case, but my entire scoring system is based in negative. The score is less than 0

  • I wish that were the case, but my entire scoring system is based in negative. The score is less than 0

    Sorry I didn't know that you are working with negative scores. I rebuild your case but with positive scores and it works fine on my end.

    You can check out the capx over here.

    LocalStorage - HighScore Capx

    Maybe you can find the issue with my example. Otherwise add the Browser plugin and Alert the current value saved in the local storage and so on (for debugging).

    Regards

    Andy

  • I figured it out. The problem was with the line you mentioned but not for the reason you mentioned. I had it so it only set a highscore when the highscore was already less than 0. since I already had a highscore in my debugger local storage it worked fine, but when I transferred over to a new environment the highscore was set to zero so it wouldn't set a new one. when I ran your capx it set my local highscore to a positive number and my games highscore stopped working in the debugger. Thanks for the help!

  • I figured it out. The problem was with the line you mentioned but not for the reason you mentioned. I had it so it only set a highscore when the highscore was already less than 0. since I already had a highscore in my debugger local storage it worked fine, but when I transferred over to a new environment the highscore was set to zero so it wouldn't set a new one. when I ran your capx it set my local highscore to a positive number and my games highscore stopped working in the debugger. Thanks for the help!

    Great news You're welcome!

    Regards

    Andy

  • Hello!!!

    Sorry, guys, but can you help me?) I have an array - "Levels". How can i save it with localstorage and then load it?

  • Hello!!!

    Sorry, guys, but can you help me?) I have an array - "Levels". How can i save it with localstorage and then load it?

    Just save it with "local storage" - set key array.AsJSON

    to load it "On key ... exists" - Load array LocalStorage.ItemValue

    Regards

    Andy

  • Because the last post was on the 6th and it's relatively new and I'm having a problem, I thought I'd ask here.

    My game on mobile saves the high score as long as I don't close the app. If I open the app again, the high score is reset to 0.

    I have the system setting the localHighScore variable to the score and setting the item to a str(localHighScore) when the game ends. When the game starts, I have a preloader set the localHighScore to int(LocalStorage.ItemValue).

    Does that make sense? If I need to show a screen grab or something I can try to do that.

  • Because the last post was on the 6th and it's relatively new and I'm having a problem, I thought I'd ask here.

    My game on mobile saves the high score as long as I don't close the app. If I open the app again, the high score is reset to 0.

    I have the system setting the localHighScore variable to the score and setting the item to a str(localHighScore) when the game ends. When the game starts, I have a preloader set the localHighScore to int(LocalStorage.ItemValue).

    Does that make sense? If I need to show a screen grab or something I can try to do that.

    Hi,

    It would be easier to help you if you provided a screen shot of your code, or better a capx example.

    Another questions, why did you save it as String to convert it later back to int? Just save & fetch it as int

    Regards

    Andy

  • Another questions, why did you save it as String to convert it later back to int? Just save & fetch it as int

    Regards

    Andy

    Because I'm not the smartest person haha, and I was following a tutorial that did it that way. I've since deleted the code and am looking at tutorials on the site to help me with it. If I have more problems, I'll post again later. Thanks for the tip!

  • > Another questions, why did you save it as String to convert it later back to int? Just save & fetch it as int

    >

    > Regards

    > Andy

    >

    Because I'm not the smartest person haha, and I was following a tutorial that did it that way. I've since deleted the code and am looking at tutorials on the site to help me with it. If I have more problems, I'll post again later. Thanks for the tip!

    Sure, you're welcome

    Regards

    Andy

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Is there any way to access the data stored by the LocalStorage plugin with Javascript like using the localStorage for the WebStorage plugin?

  • hola quisiera que mi Ranking se guardara localmente, tengo un juego para pc y quiero que mi Ranking se guarde en un documento de texto, localmente como lo hago..?

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