Having trouble with webstorage for json array vs variables

Get help using Construct 2

Post » Sat Apr 04, 2015 11:32 am

Hi guys,

I will need to save data into an array as a json file because there will be possibly over a thousand data to be stored, so saving as individual variables might not be the way to go. However, I am having problem in that when I save the array and load it, it works fine as I move between layouts, or restart the game using a restart button inside the game. However, when I exit the game and than run it again, the data is not available anymore. I made a capx below.

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

Please run the "main" layout. Press on the play button and it will bring you to another layout. Press any of the blue boxes to increase the value. The values for button 1 and 2 are being saved to an array and stored to webstorage as a json file. The third one is saved using normal webstorage. Switching between layouts or restarting by pressing the green button in the main layout shows everything works fine. But when you exit and restart, only the third one saved with normal webstorage is displayed correctly.

I am sure I must be doing something wrong, could anyone please help point out what I am doing wrong?

Also out of curiosity, does the amount of data stored and being saved and retrieved affect the performance of the game? For example, 10 000 individual webstorage key for a mobile game, will there be a noticeable effect on performance?

Thanks everyone!
B
46
S
23
G
31
Posts: 693
Reputation: 20,637

Post » Sat Apr 04, 2015 12:17 pm

On start of layout, rather than load the array from string "A" (which is undefined) you need to load as json from WebStorage.LocalValue("A").
A big fan of JavaScript.
B
76
S
20
G
76
Posts: 2,285
Reputation: 47,554

Post » Sat Apr 04, 2015 12:50 pm

@Colludium, thank you so much, that was indeed the issue.
B
46
S
23
G
31
Posts: 693
Reputation: 20,637


Return to How do I....?

Who is online

Users browsing this forum: R0J0hound and 9 guests