Headspritestat

From EDukeWiki
Jump to navigation Jump to search

headspritestat sprite statnum

Returns the ID of first sprite in the list of sprites with a matching statnum. This command can be used to scan through all sprites of a certain type. The nextspritestat and prevspritestat commands should be used to go forward and back through the list of sprites. See also headspritesect, which is identical in operation but based on the sprite's sectnum rather than its statnum.

Note: sprite is the gamevar to store the sprite ID in.

Example

This state will count the number of actors (sprites with a statnum of 1) currently in the map and put the result in the gamevar NUM_ACTORS.

gamevar SPRITE_ID  0 0
gamevar NUM_ACTORS 0 0

defstate count_actors
set NUM_ACTORS 0
headspritestat SPRITE_ID 1
whilevarn SPRITE_ID -1
{
  add NUM_ACTORS 1
  nextspritestat SPRITE_ID SPRITE_ID
}
ends