I wondered if Unityscript might be getting confused by the colon. Rather than assigning the nested hashtable to name, it thinks I’m telling it what type “name” is.
But if that were the case, I would expect this to work:
var dict = {};
dict.Add("name", {"first":"John", "last":"Smith"});
It’s not a bug, it’s to do with not having dynamic typing in Unity iPhone. If you put “#pragma strict” at the top of the script in regular Unity, you get the exact same error.
Smag, this actually works if “Hashtable” is capitalized correctly :), but it doesn’t work if the hashtables are more than 2 levels deep.
For instance, the following doesn’t work:
var dict = {"level1":{"part2":{"enemy": "soldier"}}};
var myenemy = (dict["level1"] as Hashtable)(["part2"] as Hashtable))["enemy"];
Debug.Log(myenemy);
I’m not much of a C# programmer, but all the examples I’ve seen on the web use the Add(“Key1”, “Value1”) notation. But I believe C# supports operator overloading, so you might be able to create something similar.