Nested Dictionaries

Started by
1 comment, last by WitchLord 7 years, 9 months ago

Is there any way to put dictionary inside a dictionary without having to initialize each dictionary first? More like:

dictionary d = {{ 'dict1': {{ 'a', 1 }, { 'b', 2 }},

{ 'dict2': {{ 'c', 3 }, { 'd', 4 }}};

instead:

dictionary subd1 = {{ 'a', 1 }, { 'b', 2 }};

dictionary subd2 = {{ 'c', 3 }, { 'd', 4 }};

dictionary d = {{ 'dict1': subd1 },

{ 'dict2': subd2 }};

Right now I'm getting error:

ERR : Initialization lists cannot be used with '?'

ERR : Reference is read-only

PS. Just realized { } is for initializer list, so it's used for arrays too and there is no way it will know what I want to construct there. Was thinking more in Python-ish way where {} denotes dictionary and [] is for arrays. Though it wouldn't hurt to make this distinction for such basic type as array/map, unless there are bigger plans for initializer list usage..


Where are we and when are we and who are we?
How many people in how many places at how many times?
Advertisement

Ok, seems that I found solution. It wasn't easy to find for such a common question, so I will provide answer here and I think that "Anonymous objects" could be referenced a bit more in documentation, for example in dictionary class that doesn't show how to anonymously embed data such as dictionary or array.

http://www.angelcode.com/angelscript/sdk/docs/manual/doc_expressions.html#anonobj

dictionary foo = {{ 'fruits', dictionary = {{'banana',1}, {'apple',2}, {'orange',3}} },

{ 'vegetables', dictionary = {{'onion', 1}, {'tomato', 2}} }}


Where are we and when are we and who are we?
How many people in how many places at how many times?

Thanks for the feedback. I'll see if I can give more examples of how to use anonymous objects (especially from the array and dictionary data type pages).

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement