IsPointerEqual

From ZDoom Wiki
Jump to navigation Jump to search

bool IsPointerEqual (int ptr_select1, int ptr_select2 [, int tid1 [, int tid2]]); — ACS version
bool IsPointerEqual (int ptr_select1, int ptr_select2) — DECORATE/ZScript version

Usage

Compares two pointers and see if they reference the same actor or not. tid1 determines the actor used to resolve ptr_select1, and tid2 determines the actor used to resolve ptr_select2. If tid1 and tid2 are equal, the same actor is used for resolving both pointers. Passing a tid of 0 for either tid* means that the check is done on the activator of the script to resolve the respective pointer.

The DECORATE version behaves the same, except that it does not accept tids, and instead, the check is done on the caller of the function to resolve the pointers.

Note that the DECORATE version of the function is to be used where an expression is expected. It is mostly useful when combined with A_JumpIf.

Parameters

  • ptr_select1: the first pointer to pass for comparison.
  • ptr_select2: the second pointer to pass for comparison.
  • tid1: the tid to determine the actor used to resolve the first pointer (ptr_select1). Default is 0, which refers to the activator.
  • tid2: the tid to determine the actor used to resolve the second pointer (ptr_select2). Default is 0, which refers to the activator.

Return value

The function returns true if both pointers refer to the same actor (equal), otherwise the returned value is false.

Examples

This imp reports two messages on death: one when it is killed by the player (player 1 in this case), and another when it is killed by anything otherwise. The function checks the imp's target at that moment and see if it was the player, jumping to the Player1Kill state if it was and printing the message.

ACTOR SomeImp : DoomImp
{
  States
  {
  Death:
    TNT1 A 0 A_JumpIf(IsPointerEqual(AAPTR_TARGET, AAPTR_PLAYER1) == TRUE, "Player1Kill")
    TNT1 A 0 A_PrintBold("Killed by something else")
    Goto Super::Death
  Player1Kill:
    TNT1 A 0 A_PrintBold("Killed by player 1")
    Goto Super::Death
  }
}