Classes:ActorIterator

From ZDoom Wiki
Jump to navigation Jump to search
Note: This feature is for ZScript only.


ActorIterator is a helper ZScript class that can obtain pointers to actors with a specific TID (and, optionally, of a specific class), which can then be put into an array or otherwise modified.

ActorIterator is similar to ThinkerIterator, with the following differences:

  • It can only search for actors, not other thinkers.
  • It requires a TID. Supplying a TID of 0 will produce no effect.

Methods

Static

  • ActorIterator Create(int tid, class<Actor> type = "Actor") (deprecated)
Instantiates an actor iterator. This was deprecated in favor of an identical method defined in LevelLocals that can be called with level.CreateActorIterator(<tid>, <type>).

Non-static

  • Actor Next()
Moves from the current actor in the list to the next and returns a pointer to it.
  • void Reinit()
Restarts the iteration.

Examples

The syntax is similar to ThinkerIterator. Can be done with a while loop:

let it = level.CreateActorIterator(100); //find actors with TID 100
Actor mo;
while (mo = it.Next())
{
	Console.Printf("Found actor \cd%s\c- with TID 100", mo.GetClassName());
}

...or a foreach statement:

foreach(Actor mo = level.CreateActorIterator(100)) //find actors with TID 100
{
	if (mo)
	{
		Console.Printf("Found actor \cd%s\c- with TID 100", mo.GetClassName());
	}
}

The result can also be cast:

let it = level.CreateActorIterator(100); //find imps with TID 100
DoomImp mo;
while (mo = DoomImp(it.Next())) //note: all actors with TID 100 must be imps for this loop to work
{
	Console.Printf("Found \cdDoomImp\c- with TID 100");
}

See Also