How do I use LocalStorage as a function

0 favourites
  • 4 posts
  • 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

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

  • So are you saying it's better to use a Dictionary, as an intercomunicator, between the interface and LocalStorage?

  • Try Construct 3

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

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

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