How do I set my local storage

Get help using Construct 2

Post » Fri May 08, 2015 2:52 pm

hello,

i need some help here.
I now how basic local storage works but i need it a bit more complex.
I have like "my wish list or shopping chart" functionality where user drag n drop his items (like inventory) but items have expire date.
so heres the question:
how can i set my local storage to store selected items and remove/delete expired ones (pass certain date)?
i have plugind DATE (i think its from rex or R0j0) and it works ok but i dont know how to create and maintain storage it self?
how to fill back the deleted blanks?

like
item1=XXX
item2=yyy
item3=qqq

now item 2 expires and gets deleted...
how to recreate again item2 with new value
item2=www
when needed and not create new
item4=www

(hope you get my point) :)


Any tips?
B
26
S
11
G
2
Posts: 669
Reputation: 5,038

Post » Fri May 08, 2015 3:04 pm

I guess when storing the items to local storage you should add the date (or expire-date) when they are added to the value..
When retrieving the local storage first check if the date isn't past the expire date..

So something like:

set local storage key is Thingyoubought to : Globalvariablenumberofitems&","&date.date

Using tokenat you can then check the date.date with the current date.date on item get
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri May 08, 2015 3:32 pm

Would make sense to cache the item data (including data) in an object like an array, and just patch in the changes to the local storage (for example you could easily do a delete in the array, then save the array as json to the local storage with no worry that you leave empty spaces).
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Fri May 08, 2015 3:48 pm

@mindfaQ
Do i set all under one key in LS?
How do i then delete the expired items from local storage?
B
26
S
11
G
2
Posts: 669
Reputation: 5,038

Post » Fri May 08, 2015 5:44 pm

you can save a whole array under one key in LS, by saving array.asjson (which you later can load into the array again by the load from json action)
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Fri May 08, 2015 5:46 pm

irina wrote:@mindfaQ
Do i set all under one key in LS?
How do i then delete the expired items from local storage?


Hi @irina
I realeased an example showing you how to setup the LocalStorage plugin for save strings (like the player name) or numeric variables like the HighScore via an array (asJSON).
It's currently on sale, so feel free to check it out here ;)

Game Template 8 - LocalStorage

If you miss a function don't hesitate to contact my. Then I'll add it ;)

Regards,
Andreas
Image Image iTunes: Match3 | Google Play: Match3
B
98
S
33
G
30
Posts: 1,117
Reputation: 27,781

Post » Sat May 09, 2015 8:50 am

@mindfaQ

thanx, your aproach works... :)
B
26
S
11
G
2
Posts: 669
Reputation: 5,038

Post » Sat May 09, 2015 10:41 am

small help needed... (mine first encounter with arrays) :)

iw set my array with height 2
0 (date,image)
1 (date,image)

how can i loop through and check in my first value (date) if is greater than my variable than delete that item?
B
26
S
11
G
2
Posts: 669
Reputation: 5,038


Return to How do I....?

Who is online

Users browsing this forum: dop2000, R0J0hound, StillSarah and 25 guests