ArrayList with jscript

I’m trying to do this in Javascript (nodesToProcess is an initialized ArrayList)

while(nodesToProcess.Count>0)
	{
		var node=nodesToProcess.Item(0);
		nodesToProcess.RemoveAt[0];
	}

But I am getting this compilation error:

“The property ‘System.Collections.ArrayList.Item’ cannot be used without parameters” … even though I list one. Anyone seen something like this before? Aside: I’m essentially using the Shift() call from the Array class here, but I want the ArrayList’s Contains() functionality… if anyone has a better alternative (ideally one without syntax issues) I’d much appreciate it, as well…

Why not this, if you’re doing it in one frame:

for(var node in nodesToProcess)
{
   // do something
}
nodesToProcess.Clear();

But the other way would be (which might make more sense if you want to yield during the loop):

while(nodesToProcess.Count > 0)
{
   var node = nodesToProcess[0];
   // do something
   nodesToProcess.RemoveAt(0);
}

}

Thanks!

I had tried the second option originally but luckily had a fundamental syntax error I hadn’t caught (['s instead of ('s).

It pays to pay attention to compiler errors.

Actually it wasn’t giving me a syntax error that I recognized; it was talking about array splicing and since I wasn’t using an out-of-the-Unity-docs collection class I figured it wasn’t fully supported for that operation.

You raise an excellent point, though. Maybe in my copious free time™ I will add a section to the wiki for debugging common compiler errors (as an alternative to searching the forums for the error string)…