How do I store an array locally for later retrieval?

0 favourites
  • 3 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • I have a game where I have redefine keys screen.

    When I redefine the keys (press key for left, key for right etc.) they're put into an array and then I loop through that array to set global variables.

    But this of course isn't persistent between sessions. What would I do to save and then load that array?

    I suppose the answer is localStorage? But I can't work out how it works. Do I need a dictionary? JSON? Something else?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I personally put them in a dictionary but array will work just fine aswell. The basic setup is pretty simple. I'd put them in functions and not "on start of layout" so you call them when you need them.

    You should keep in mind all possible cases that can happen. E.G. the first time the player starts the game the item does not exist. You can check first if the item exists and if it's missing you load a default configuration at first etc.

  • Brilliant, that's really clear and helpful. Thanks!

    So you just save the whole array/dictionary to one item in LocalStorage? That makes things much clearer.

    Cheers!

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