A really big problem with the Local Storage

0 favourites
  • 10 posts
From the Asset Store
Basic Plugins for Firebase Authentication, Realtime-Database, Firestore, Cloud Storage
  • I have used Local Storage in others projects to manage levels and badges, but something wrong is happening, maybe because I'm storing an array for the first time. Sometimes, when I return to the levels menu, I lost some registers (5 or more) that I have achieved. It happened during the preview (NW.js) and several times when I'm testing on my iPhone. I cannot post my capx, but I captured some screenshots about the event sheets involved in this issue. I hope that someone can help me to fix it. Thanks in advance.

  • If you call "Exists", you don't need to call "Get" in "On exists", it's already there at that point, so just "Load" is fine.

    Doing a set in a For loop is a bad idea. You only need to save at the end of the loop. Having said that, your For loop doesn't change the array, so there is no reason to save at all. In "on touch", you call Set twice.

    LocalStorage is an expensive operation. You want to call Set as little as possible, and only when necessary. If you've queued up dozens of saves and switch layouts, it's possible, that not all of the data is saved, as it's still trying to catch up in the background.

  • Hi blackhornet

    Thanks for all the explanations. I'll remove the unnecessary "sets" but I didn't understand what I do to set the array values correctly. Maybe in the last part of the ES, next to "Array > Set value at currentLevel..."?

  • Yes, that is where the data is changing, so that is where you could save, just like "Level_key", it is no different. An optimization could be to use Array(0) as your level-key and only deal with saving the array, instead of breaking into two items. Since I assume your levels start at 1, you have an empty slot sitting there anyway.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks.

    I've a doubt about the optimisation. If I change as you said, it can possibly improve the game performance or at least doesn't compromise it? I ask because I didn't know that localstorage was an expensive operation and I've 12 more localstorage items (for each in-app product, for ads control, sound control, etc). So, I believe that I'll have a lot of work to make this changes but If will improve my game, I'll do it. I only need some orientation of how to include all this items in the same array (using its height?) and I'll appreciate an example (a capx is not necessary).

  • In that case, use a dictionary for the other items. That way you have one array and one dictionary. Much better than coordinating 12+ variables.

  • Thank you.

  • blackhornet

    After the changes (without taking into account the dictionary implementation) the next level of the menu remains blocked even the previous mission is completed. As noticed, it happens when the array is loaded (I disabled the array loading to test it). Any idea about where's the problem?

  • I included an action after the increment of the level variable that solved this issue. However I'm not very confident that was the right solution. Is it right?

  • It depends on what your level-unlocked code looks like, but if it needs to be at least 1, then this should be fine.

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