How do I use LocalStorage as a function

Get help using Construct 2

Post » Mon Jun 29, 2015 1:57 pm

I have 30 events using LocalStorage:

1.- On Item1 missing > Set var1 to 0
2.- On Item1 exists >Get item "item1value"
3.- On item1 get > Get Item LocalStorage.ItemValue

same for object 2, 3, 4, 5 and 6:
1.- On Item6 missing > Set var1 to 0
2.- On Item6 exists >Get item "item6value"
3.- On item6 get > Get Item LocalStorage.ItemValue


I'd like to optimize all of them in a single function, such as:
1.- On Item missing > Set function (familyItemIID.value to 0)
2- On item exists > function Get touchedItemvalue
2- On item get > function Get Item LocalStorage.ItemValue

Any ideas?
Thanks
B
12
S
3
G
1
Posts: 347
Reputation: 2,866

Post » Mon Jun 29, 2015 4:36 pm

Probably you shouldn't use LocalStorage like this. Think of it as a distant store with very slow connections, you don't want to be sending stuff back and forwards all the time.

Practically I would load a single item at the start and save it back (say) at the end of each game, with all the data json encoded using a dictionary.
My tutorial through development blog is at http://myconstruct2dev.blogspot.co.uk/
B
12
S
3
Posts: 221
Reputation: 1,328

Post » Mon Jun 29, 2015 5:53 pm

So are you saying it's better to use a Dictionary, as an intercomunicator, between the interface and LocalStorage?
B
12
S
3
G
1
Posts: 347
Reputation: 2,866

Post » Mon Jun 29, 2015 6:05 pm

If your game or app or whatever is accessing and updating data used in local storage with any frequency it is probably better off in a cache - unless it is multiplayer and more than one person is updating it of course. Once read into a dictionary it can be accessed immediately.
My tutorial through development blog is at http://myconstruct2dev.blogspot.co.uk/
B
12
S
3
Posts: 221
Reputation: 1,328


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 5 guests