Manual iterating again

Monkey Forums/Monkey Programming/Manual iterating again

Shinkiro1(Posted 2011) [#1]
I am not exactly sure how monkey.list works, but from what I understand each time one uses "EachIn" it creates a new Enumerator<T>.
As I do not want that to happen -> Is it possible to allocate one global Enumerator for 1 list:
Global SpriteEnumerator := SpriteList.ObjectEnumerator()

and then can I use this Enumerator without having to update it (when adding or removing nodes to this specific list)?
Local sprite:Sprite
While SpriteEnumerator.HasNext()
  sprite = SpriteEnumerator.NextObject()
  sprite.DoSomething()
End



Samah(Posted 2011) [#2]
Not with Monkey's List class. Diddy's ArrayList allows you to manually reset enumerators if you wish to cache them. Note that it enforces concurrency checks, so don't manually add or remove things within the loop. Get the enumerator to do that for you.

http://code.google.com/p/diddy/wiki/ArrayList