Classes:ActorIterator: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
→Examples: CreateThinkerIterator was used instead of CreateActorIterator. Added a note of caution about 3rd example |
→Examples: Switched from spaces to tabs as in most other ZScript examples |
||
| Line 24: | Line 24: | ||
while (mo = it.Next()) |
while (mo = it.Next()) |
||
{ |
{ |
||
Console.Printf("Found actor \cd%s\c- with TID 100", mo.GetClassName()); |
|||
} |
} |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
| Line 31: | Line 31: | ||
foreach(Actor mo = level.CreateActorIterator(100)) //find actors with TID 100 |
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()); |
|||
} |
|||
} |
|||
} |
} |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
| Line 43: | Line 43: | ||
while (mo = DoomImp(it.Next())) //note: all actors with TID 100 must be imps for this loop to work |
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"); |
|||
} |
} |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
Latest revision as of 15:50, 4 February 2026
| 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");
}