How do I stop local storage value resetting itself?

0 favourites
  • 6 posts
From the Asset Store
Basic Plugins for Firebase Authentication, Realtime-Database, Firestore, Cloud Storage
  • So I have an android game that records two values, the Highest score, and the longest time.

    The problem is, is that the longest time resets its randomly. I been testing my game for two months now, and the longest time resets itself, without no cause. It will display the longest time for 2 to 3 weeks, and then it will reset self.

    The thing is, is that the Highest Score, does not reset itself, and displays the highest score without a problem.

    It does this in the browser testing, and in app testing.

    This is the best score display.

    Hopefully someone can teach me a safer method of storing long term data, or just correct what I did wrong. It is driving me crazy lol.

  • I'm not sure if this logic would even work, the itemvalue comes from a 'get' which you never use. Sure you are checking if the items exist in local storage but the problem might come when you set the global variable to itemvalue, the itemvalue could be 0. I assume you are seeing 0 if you say it resets. Also I don't think it's normal to be checking and setting it in two different places, why do this with duplicate logic?

  • lionz The logic is to make sure that the game score would be recorded in the game space, and then stored in localstorage, and whatever the numerical value is, would be displayed in the records layout.

    It sounds logical in my head. But in the way you describe it, what I am doing is not best practice. Maybe I don't need to reduplicate like you said.

    But it still begs the question why the Highest score function works while the longest time resets. Anyways, I'll update this post some time in the future if the problem goes away.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Is it resetting though? You didn't answer the question about what you're seeing to know it resets. In the records layout which I assume is the second screenshot you can just use the global variables there is no need to look again into local storage and also I think that would fix the issue.

  • lionz To be honest, I don't really know what is the cause of the random reset of best time recorded. It happens in a 2-3 week interval. I don't think its my action causing the reset. Maybe just my fault in my code?

    Honestly, I chose to use local storage, as I want the data to persist. I don't know if global variables can remain static, even after the app closes.

    I ended up doing this

    I will update this post in a few weeks if successful and the time recorded works as I want it to function.

  • The global variables will not retain the value when you close the app, my point is that you only need to grab the values from local storage one time because you set them to a global variable while the app is running. You want to minimize the chance for bugs happening, load from local storage one time in a session not every time you change layout.

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