for (var x in object) giving x = System.Collections.DictionaryEntry

So i have an object called listOfStuff, to which i add variables through

function storeNew(item,value){
	listOfStuff[item] = value;

then i have a loop function:

   function listData(){
        	for(var x in listOfStuff){
        		Debug.Log(x + "is worth" + listOfStuff[x]);

which should write all the data added to the object, so

//should result in: 
//"banana is worth 2"
//"diamond is worth 1000"

this only logs System.Collections.DictionaryEntry, why is that?

Okay so I don’t really use unityscript any more and hadn’t realized the meaning of the syntax but on a second look (and from the name of the error!) I’m guessing it is the unityscript equivalent of a C# dictionary so ~hopefully~ the following might work:

var listOfstuff = {};

function Start () {
	listOfstuff["test"] = 1;
	listOfstuff["test2"] = 2;
	for(var entry in listOfstuff){
		Debug.Log(String.Format("{0} is worth {1}", entry.Key, entry.Value));

so basically the important part is that to get teh first part you use entry.Key and the second part entry.Value!

Hope that helps, sorry for my rather sarky comment, I was definitely in the wrong :slight_smile: