Headspritestat

From EDukeWiki
Revision as of 21:12, 19 August 2021 by TrooperDan (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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