Multidimensional Dictionary

0 favourites
  • 5 posts
  • Hi all,

    So I've loaded a multidimensional json file into a dictionary. That works fine. When I log the dictionary back out as json then everything is intact.

    However there appears to be no way to access nested elements? Any ideas if this is supported?

  • I'd say it's not supported.

    But there's a way to fake multidimensionality in dictionary and array

    You can save as a value, the JSON from a dictionary or an array

    For instance

    if I have an array named levels

    and one dictionary per mob in my game (containers) named mobData

    And let say I want to save everything in my level array

    You can do

    system: foreach mobs:
      levels: set value at (level,loopindex) to mobData.AsJson

    And to read this data you just need a temporary dictionary (tmpDict)

    So to get the data of the 3rd mob of level 3 you would do something like:

      tmpDict: Load levels.At(2,2)

    And then you can access any key you want hence faking and array of dictionary. You could have dictionaries of dictionaries of dictionaries, or array of dictionaries of array, any combinaison.

    The only downside is that the JSON is harder to make by hand (multiple level of escaping) and also the access is a bit expensive since you have to load a JSON each time

  • It might be nice if we had a json object that was parse-able, but with out the mandatory prefix that array, and dictionary have.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yann hmm I see what you mean. My problem is mapping a JSON array to a dictionary/object. Looks like I'll have to flatten it serverside and remap which is a pain.

    Edit -> ooh I've just noticed there's regex system expressions in the latest build! Pretty sure I can get something working using those :D

    Edit 2 -> Okay that would have gotten messy fast. Serverside is the way to go.

    Finally got it working using rexrainbow's brilliant Hash Table Plugin. Multidimensional was spelt wrong so it didn't show up in searches. Works perfectly!

  • thehen

    as a rule of thumb, regex are no good for parsing tree like structures.

    (you'll see a lot of angry answer for parsing xml with regex on stackoverflow :D.. for JSON it's the same idea)

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