• Advertisement
Sign in to follow this  

Nested Dictionaries

This topic is 640 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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..

Edited by noizex

Share this post


Link to post
Share on other sites
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}} }}

Edited by noizex

Share this post


Link to post
Share on other sites

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).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement