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

Get help using Construct 2

Post » Thu Sep 08, 2016 1:53 pm

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!
B
11
S
1
Posts: 42
Reputation: 565

Post » Thu Sep 08, 2016 4:33 pm

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
B
46
S
16
G
74
Posts: 2,089
Reputation: 44,187

Post » Thu Sep 08, 2016 6:43 pm

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.
B
11
S
1
Posts: 42
Reputation: 565

Post » Thu Sep 08, 2016 8:45 pm

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.
B
46
S
16
G
74
Posts: 2,089
Reputation: 44,187

Post » Thu Sep 08, 2016 9:17 pm

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.
B
11
S
1
Posts: 42
Reputation: 565

Post » Thu Sep 08, 2016 10:11 pm

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

B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Sep 09, 2016 9:24 pm

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!
B
11
S
1
Posts: 42
Reputation: 565


Return to How do I....?

Who is online

Users browsing this forum: Baidu [Spider], brunopalermo, David181 and 8 guests