Store an Entire 1d/2d Array on User's Device.

0 favourites
  • 7 posts
From the Asset Store
A futuristic device, can be used as radarscreen, optionscreen, infodisplay, research device, ...
  • Dear Honourable Construct 2 Programmer,

    How can I store an entire array in a 1d version as well as a 2d version? What’s the best way to do it? Perhaps local storage is the right tool to do it. I don’t know how though. Can you please demonstrate and include your capx?

    What i want to do is to allow a user to type in multiple strings and i put that into an array. I got this part down. Now i want this data to be available any time a user comes back to play my game until the data is changed by the user. Please note that i don’t know how many strings a user puts into my array. In other words, the number of strings is indefinite, it is not pre-defined. Then i need to store that array on the user’s device, whatever the device may be. This is the part I am stuck at.

    Thank you in advance!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hello,

    It is as simple as using the 'save' and 'load' slot commands. All the array values will be saved at their current state at the time of 'save'.

    Check out this link for how to easily save and load a game : https://www.scirra.com/tutorials/526/ho ... -savegames

  • Thank you for your reply. There is no need to save the entire game in my case. I only need to save some data a player provides before the player begins playing the game. Besides, it may be quite handy to know how to "individually" store the array for the purposes of storing high score too.

    Perhaps i should mention I did find this thread titled "How do I save an Array using the new Local storage plugin?" on this forum, but i find it both inconclusive and i cannot make use of it in a proper way.

    Therefore, i still feel i need help outlined by my initial post.

  • No problem, here is an example capx using Dictionaries : https://www.scirra.com/tutorials/4836/n ... dictionary

    You could use the Dictionary values to store data or modify it to use an Array instead.

  • Thank you again, this is not exactly what i asked for but it does give me something to work with until a more straightforward solution is suggested if any at all. My concern is that what may seem to be modifiable, does not necessarily have to lend itself to be modified. Right now i take it as a good sign of possibility.

  • Store the array as json in a local storage key. Load it back when needed.

    What about:

    https://www.dropbox.com/s/n714arr2bjx5e ... .capx?dl=0

  • Thank you for your invaluable contribution and for sharing. I suppose this actually answers my request. I will work with the file you provided. It appears there is a straight way from your capx to my goal!

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