We need a way to loop through the Webstorage

Discussion and feedback on Construct 2

Post » Sat Aug 23, 2014 9:53 pm

Hey all,

A mysteriously missing feature from C2 for some time now is the ability to loop through all the webstorage values for a game. This might seem a bit useless, so I'll try to illustrate my current predicament.

I have a 'save slot' system which works by prefacing every webstorage value with a slot value - e.g. "Score" becomes "1_Score" for slot 1, "2_Score" for slot 2. I set up functions to do this all automatically, and it works well.
The problem comes when I'm trying to clear a slot by removing all the webstorage values prefaced with that slot value. I've been attempting to find a way to workaround, and it all comes down to the fact that we can't loop through the webstorage like we can for a dictionary, even though the two systems are functionally identical.

Any thoughts?
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,679

Post » Sat Aug 23, 2014 10:10 pm

Basically I put all my variables into a dictionary and then save the dictionary in json format into the slot.

I can loop over the slots to do things like find an empty slot or whatever.

To clear a slot I just set it to an empty string (thus overwriting the json dictionary saved there).
B
21
S
5
Posts: 196
Reputation: 1,974

Post » Sat Aug 23, 2014 10:13 pm

@ggibson1 that's not a bad idea. I might give that a try...
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,679

Post » Sun Aug 24, 2014 10:03 am

you can also I think load the webstorage into a dictionnary directly, then load it back to the webstorage.
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 10 guests