Quantcast
Channel: Answers by "dubbreak"
Viewing all articles
Browse latest Browse all 68

Answer by dubbreak

$
0
0
Since you aren't getting an indexing exception it means the objects are in there. Problem appears to be that your array you are pushing them into isn't typed (should be an array of CountryNodes). I don't do JS, and some quick looking doesn't show a way to type the "array" (it's actually a list.. since it auto resizes etc). The problem is: when you get your object out it is just an object, so at runtime it doesn't know whether it has your fields or not. Solution? Cast you object before accessing the fields. A nice way would be to use a foreach loop that casts as you go. foreach (var countryNode : CountryNode in countryNodes) { Debug.Log(countryNode.nameCountry); } //or using existing loop for ( var i =0; i < countryNodes.length; i++) { var countryNode : CountryNode = countryNodes[i]; //helps type inference along Debug.Log(countryNode.nameCountry); } Other solution: Use a typed structure. var countryCodes : List.<CountryNode> = new List.<CountryNode>(); //in code that adds items countryCodes.Add(myNode); //adds to end - push not avail in list, need to use stack for that These type inference issues are one of the reasons I'm not a huge fan of unity's JS (looking) scripting language (that and not being able to declare events). It's a stumbling block I don't think someone would run into in C#. They are trying to emulate a dynamically typed language (JavaScript / ECMAScript) in a strongly typed environment. It's just syntax that looks like JS (just like VB.net resembles VB6, but is really it's own beast that is closer to C# than the old vb). Anyhow that's neither here nor there. Let me know if this helps. If not I'll whip out the ol' JS editor and get it working.

Viewing all articles
Browse latest Browse all 68

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>