WebStorage VS Local Storage

Discussion and feedback on Construct 2

Post » Wed Apr 22, 2015 10:15 pm

Since the latest release introduces Local Storage, I was wandering what is the best way to migrate from WebStorage to the new Local Storage, especially for existing games.
Thanks
B
37
S
9
Posts: 63
Reputation: 2,255

Post » Wed Apr 22, 2015 10:31 pm

The easiest way to do it is probably:

1. make a dictionary called 'storage' or something
2. replace all webStorage references with references to that dictionary (or, if you really want to go the extra mile, replace them all with function calls that then reference the dictionary)
3. save/load the entire dictionary from LocalStorage at specific times (e.g. on startup, on exit, at the start/end of every level, etc).

That way, you can keep using storage references without needing to worry about the whole async issue.

Of course, if you are using webStorage to store MB's of information, this approach might not be the best.
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,699

Post » Wed Apr 22, 2015 10:39 pm

I'm using x, y, arrays for game "mechanics" so going about using dictionary might be a challenge. Also I'm concern about user existing data that needs to load from Webstorage when the game start.
B
37
S
9
Posts: 63
Reputation: 2,255

Post » Wed Apr 22, 2015 10:42 pm

for saving highscore and load it from local storage i prefer webstorage
i still dont understand the local storage actions
B
46
S
16
G
8
Posts: 802
Reputation: 8,351

Post » Thu Apr 23, 2015 12:26 am

What do you need to save in webStorage that you need a whole array of values?
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,699

Post » Thu Apr 23, 2015 1:54 am

One of the arrays I have is with all the game settings like Level, XP points, Items you bought, timestamps erc... I also have X, Y, arrays with more user data.
Using arrays is much easier that using dictionary as long as you keep a chart with what each value is for :)
B
37
S
9
Posts: 63
Reputation: 2,255

Post » Thu Apr 23, 2015 3:04 am

You can store arrays in dictionaries! Unpack/pack them during saving/loading.
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,699

Post » Thu Apr 23, 2015 7:18 am

sqiddster wrote:(or, if you really want to go the extra mile, replace them all with function calls that then reference the dictionary)


Out of curiorisity, why or in what situation would you use that? (I'm still trying to improve my usage of Fuctions.) Thanks! Image
B
152
S
75
G
21
Posts: 1,795
Reputation: 23,285

Post » Thu Apr 23, 2015 8:07 am

@alspal it's an absolute lifesaver when you need to move to a save slots system. All of the webstorage references in Airscape are function calls that pulls the data from the current save slot.
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,699

Post » Thu Apr 23, 2015 2:26 pm

Alternatively if you don't need to publish to the Chrome Web Store, just keep using WebStorage. Local Storage is a good idea for the long term and you should use it for any new projects, but if it proves particularly difficult to change over then WebStorage probably isn't going to disappear any time in the foreseeable future. Also if you have already published a game, Local Storage can't read data previously saved by WebStorage, so that might be a dealbreaker.
Scirra Founder
B
402
S
238
G
89
Posts: 24,644
Reputation: 196,095

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 5 guests