project file <--> web storage

Get help using Construct 2

Post » Fri Sep 20, 2013 12:48 pm

I would like to have a confirmation on this before I build something that goes the wrong direction.

Scenario:
An app needs a lot of initial values for various items. But those values will change depending on the user's actions. When leaving the app and later return, the last state of the values should be restored rather than the initial one's.

My logic:
I save a dictionary with the initial values as a JSON file and import it as a project file. On start of layout that JSON file is requested using Ajax.Request(project file) and then loaded via Dictionary.Load(Ajax.LastData)
When user changes values I store the dictionary's JSON string as a value to a key in web storage.
Next time the user starts the app, an on-start-of-layout-event checks if the key exists in web storage via local-key-exists-condition. If true I load the key's value to the dictionary via dictionary.Load(webstorage.localvalue(key))

Can anyone confirm that this is correct (without spending hours on testing it, just based on experience)? Is there a simpler way?
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Fri Sep 20, 2013 12:55 pm

Sounds like the system save might work for you.
Image ImageImage
B
171
S
50
G
179
Posts: 8,382
Reputation: 113,458

Post » Fri Sep 20, 2013 6:40 pm

I also thought about it, but system save introduces other issues with this app that I would like to avoid.
I'll wait a while if someone has already worked with JSON, Ajax and web storage in a similar way and can confirm, else I'll do some experiments.
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Fri Sep 20, 2013 10:04 pm

@tulamide
ummm. B. I. N. G. O,   B. I. N. G. O, and bingo was his name oh!

umm. yes that will work. although I tend to forgo the original export to file. but yes. that's exactly the process you want to do.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,038

Post » Fri Sep 20, 2013 11:47 pm

@jayderyu
Thank you very much! It's a relief that I can do it this way.
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 23 guests