How do I correctly use local storage or there is something better?

0 favourites
  • 14 posts
From the Asset Store
Basic Plugins for Firebase Authentication, Realtime-Database, Firestore, Cloud Storage
  • I'm writing you guys to check with someone more expert if there is a correct way to use local storage or if is better to use something different.

    My game is a click/tap game divide in 2 layout (entrancetitle one, game one)with at least 30 global variable to store. I tried to arrange single event for every single global variable, but they are not loading at start of the game it takes at least 3/4 minutes to get the value and the game is already started.

  • Hey,

    it shouldn't take 3/4 minutes to load a few vars from local storage.

    Maybe post your code, there should be something wrong.

    I also wouldn't recommend to store 30 vars in the storage.

    Use a "Dictionary" and store your vars there. Then save the dictionary in the local storage. Now you only have 1 item to save / load.

    Best regards!

    Edit: You can check out how the local storage works in the C3 manual: construct.net/en/make-games/manuals/construct-3/plugin-reference/local-storage

  • So first start of layout I'm doing this

    Than this

    then on start of the second layout this

    For every single global variable

  • After than this shuold be this image

  • Don't do this. Use a Dictionary as CGamez and the Local Storage manual itself suggests.

  • Here is an example showing how to save many variables with a dictionary.

    howtoconstructdemos.com/easily-save-multiple-values-in-local-storage

    .

    There's probably some mistake somewhere else in your code. Because even if you are storing 1000 keys like that in Local Storage, it shouldn't take that long to load them.

  • so first of all thanks for the answer, I tried to use the dictionary as suggested and I did like image

    then everytime that my global variable change I setup once again the dictionaryvalue

    but thay not stored when i close and reopen the game. what i'm doing wrong?

  • Generally you'd make a save function, when the game closes, or a level completes, copy all of your variables into the dictionary, and save the dictionary. Then on startup, you load the dictionary and copy the values back out.

    There are other ways, but this is the simplest and safest.

  • but thay not stored when i close and reopen the game. what i'm doing wrong?

    The dictionary will not keep your data between sessions, you still need to save it to Local Storage! It just helps to save lots of values at once, because you don't need a gazillion of events. Take a look at that demo I posted.

    Also, why all your keys have "?" at the end?

  • Now i have a question. when i have lots of variable in my project then i do save them in array. So do i need to save them into dictionary, or Array is a good alternative to save variables?

  • luckyrawatlucky They are both good. Dictionary may be more convenient and user-friendly because you can give descriptive names to the keys.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • oh!kay I got the point.

    Thanks

  • > but thay not stored when i close and reopen the game. what i'm doing wrong?

    The dictionary will not keep your data between sessions, you still need to save it to Local Storage! It just helps to save lots of values at once, because you don't need a gazillion of events. Take a look at that demo I posted.

    Also, why all your keys have "?" at the end?

    Ok I will try like you said.

    The "?" At the end is just something for me to not get confused with global variable name

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