CheckClass

From ZDoom Wiki
Jump to navigation Jump to search

bool CheckClass (string classname [, int ptr_select [, bool match_superclass]])


Note: The feature described should only be used in DECORATE code and should be considered deprecated in ZScript code where the is keyword and GetClass function should be used instead.

Usage

Checks the specified pointer's actor class name and see if it matches the specified class name passed to the function.

Note that this function is to be used where an expression is expected. It is mostly useful when combined with A_JumpIf.

Parameters

  • classname: the class name to check against.
  • ptr_select: the pointer to check its class name. Default is AAPTR_DEFAULT, which points to the caller of the function. See actor pointers.
  • match_superclass: if true, enables "parent" class checking. Default is false.

Return value

The function returns true if the specified pointer's actor class name matches the specified class name, or if the pointer is derived from said specified class if match_superclass is true. Otherwise, the returned value is false.

Examples

When this zombieman acquires a target, it will check the class name of its target and see if it is the actual PlayerPawn class, logging to the console "Target is a protoplayer" if it is. If the target is not the PlayerPawn class, it will then check to see if it is derived from said class, logging to the console "Target is some kind of player" if it is. If the target fails both checks, it will simply log "Targeted something else?".

ACTOR TestZombie : ZombieMan replaces ZombieMan
{
  States
  {
  See:
    // Jump to SeeClass if target is PlayerPawn
    POSS A 0 A_JumpIf(CheckClass("PlayerPawn", AAPTR_TARGET), "SeeClass")

    // Jump to SeeSubClass if target is derived from PlayerPawn
    POSS A 0 A_JumpIf(CheckClass("PlayerPawn", AAPTR_TARGET, TRUE), "SeeSubClass")

    // Target failed both checks. Log the following.
    POSS A 0 A_Log("Targeted something else?")
    Goto Super::See

  SeeClass:
    POSS A 0 A_Log("Target is a protoplayer")
    Goto Super::See
  SeeSubClass:
    POSS A 0 A_Log("Target is some kind of player")
    Goto Super::See
  }
}