How do I set dictionary?

0 favourites
  • 10 posts
From the Asset Store
A whole set you need to create a gorgeous winter 2d game
  • I'm rather confused on dictionaries. I think its just a mind blank but I've been tryna figure it out the last hour and a half and I can't.

    I have a file called "achievements.json", I want to be able to set a dictionary to this so I can keep track of the completed achievements. I need this dictionary to be able to be edited in 2 different areas (menu and game) and I need to be able to read this data in the achievements tab. Everything I try for this just seems to complicated.

    So yeah question is, how can I set a dictionary to a json file inside the project?

  • Your post is worded slightly ambiguously - I'm not 100% sure if you're trying to put dictionary data in a JSON file or load a JSON file into a dictionary. I'm guessing it's the latter?

    There's two parts to this: getting the contents of the file, and putting them into the dictionary.

    To get the contents of achievements.json, you can use the AJAX plugin > Request achievements.json (tag "loadAchievements")

    AJAX is asynchronous, meaning this request will take a small but indeterminate amount of time to complete. That means we have to test to find out when the data has been loaded and is ready to use.

    AJAX > On "loadAchievements" completed: Dictionary > Load from JSON string AJAX.LastData

    Note the Dictionary accepts JSON in the following format:

    {"c2dictionary":true,"data":{"item1":"whatever","item2":0,etc}}

  • okay, also to save this data i should save the dictionary to local storage correct?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yes, you can export the whole Dictionary as a JSON string and put it in LocalStorage.

    I guess you may or may not need to do this given that your JSON data is already saved in achievements.json? Not sure how your setup works :)

  • okay thank you!

  • Why doesn't this work? My dictionary isn't receiving any data.

  • Dictionary shouldn't be loading "Achievements.json". It doesn't know what that is. You need to tell it to get the data that you just pulled via AJAX.

    It should be Dictionary > Load JSON: AJAX.LastData

  • what about with the third event?

  • Dictionary needs to load from LocalStorage.ItemValue

  • okay thank you!

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