Multidimensional Dictionary

Get help using Construct 2

Post » Fri Jun 28, 2013 11:47 am

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?
Moderator
B
72
S
14
G
11
Posts: 900
Reputation: 11,910

Post » Fri Jun 28, 2013 3:48 pm

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[code]system: foreach mobs:
levels: set value at (level,loopindex) to mobData.AsJson[/code]
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:[code] tmpDict: Load levels.At(2,2)[/code]
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


Yann2013-06-28 15:49:48
B
64
S
22
G
14
Posts: 1,482
Reputation: 16,457

Post » Fri Jun 28, 2013 4:30 pm

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.
Image ImageImage
B
166
S
49
G
154
Posts: 8,103
Reputation: 100,227

Post » Fri Jun 28, 2013 8:34 pm

@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! thehen2013-06-28 21:29:37
Moderator
B
72
S
14
G
11
Posts: 900
Reputation: 11,910

Post » Sat Jun 29, 2013 3:13 pm

@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)
B
64
S
22
G
14
Posts: 1,482
Reputation: 16,457


Return to How do I....?

Who is online

Users browsing this forum: ankas, mekonbekon and 12 guests