How do I set my local storage

0 favourites
  • 8 posts
From the Asset Store
"Easy Local Notifications" enhances games with customizable local notifications.
  • 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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

  • 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).

  • mindfaQ

    Do i set all under one key in LS?

    How do i then delete the expired items from local storage?

  • 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)

  • 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

  • mindfaQ

    thanx, your aproach works...

  • 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?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)