Headspritestat: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
'''headspritestat''' ''(gamevar)sprite'' ''statnum''
'''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]].
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


[[Category:EDuke32 specific commands]]
[[Category:EDuke32 specific commands]]
[[Category:Sprite manipulation]]
[[Category:Sprite manipulation]]

Latest revision as of 22:12, 19 August 2021

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