How do I pull certain data from a saved dictionary?

Not favoritedFavorited Favorited 1 favourites
  • 7 posts
From the Asset Store
Match the similar cards with each other and free all animals!
  • In my game I save all players starter health in dictionary, players health change by items or level ups and so I update the dictionary then. How do I get the most current health updated and if health is not updated then get the original starter values from dictionary.

    Would anyone have a clue on how to do this as I cant get this to work and this is what I have so far. Btw the players "new health" and health bar can be ignored in the code as they dont pertain to the dictionary

  • You are not using LocalStorage correctly. You can't use "get" action without checking if an item exists first. Also, you need to load the dictionary from AJAX.LastData LocalStorage.ItemValue, not from the tag.

    On start of layout: LocalStorage check item "tag" exists
    
    LocalStorage on item "tag" exists: Dictionary load from JSON string LocalStorage.ItemValue
    
    LocalStorage on item "tag" missing: Dictionary set default values to keys
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I tried what you said and it would not work with load ajax last data. I changed it to load from localStorage.itemvalue and it works as it saves the dictionary but the health keeps going to the original value and not the new and updated on start.

    Not too sure on why at the moment

  • load ajax last data. I changed it to load from localStorage.itemvalue

    Sorry, of course it should be localStorage.itemvalue

    LocalStorage events are asynchronous, meaning that you need to wait for them to finish. The last event on your screenshot doesn't wait and sets player's health to the default value from the dictionary (while the data from LS is still loading). I suggest you change it to a function:

  • I have done this and the issue with this is if their is no save it does not go to the default values, also How do we set the keys if we have not added the keys. I have changed set to add as well and it does not go to default values

  • Ah, yes, "Dictionary set key" only works if the key already exists. I always use "Add key".

    If it still doesn't work even with "Add key", please post a new screenshot of your events.

  • Okay not sure what I did but I just removed all saves and reopened and closed client and it seems to be working now using this boolean. Will probably go ahead and work on using a function call instead but for now it works I think, Thanks

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