FindState
Jump to navigation
Jump to search
Note: This feature is for ZScript only. |
clearscope native state FindState(statelabel st, bool exact = false)
Usage
Obtains a pointer to the first Actor state in the specified state sequence. This can be returned in an anonymous function or a function that returns a state.
Note: If called in PSprite context (i.e. from a Weapon state or action function) and you need to find the state on the weapon, remember to prefix this function with invoker.
, because in PSprite context invoker
is the weapon, whereas self
is the owner of the weapon. Alternatively, simply use ResolveState—it can guess context automatically.
Parameters
- statelabel st
- The name of the state sequence, such as "Spawn", "Missile", etc.
- bool exact
- Finds the exact state passed to st, this is useful for finding substates like the ones that the Pain and (X)Death states support, or custom substates like "Jump.Up:". For example, it can be used to find if the caller has a Pain.Electric state in particular.
Examples
This version of the ChaingunGuy immediately stops firing if its target is either null, or dead, or over 1024 units away from him:
class ChaingunGuyWithDistanceCheck : ChaingunGuy
{
Default
{
MaxTargetRange 1024; // Won't try attacking targets beyond this range
}
States
{
Missile:
CPOS E 10 A_FaceTarget;
CPOS FE 4 BRIGHT A_CPosAttack;
CPOS F 1
{
// If the target pointer is null, or the target is dead,
// or distance to it is 1024 or more units, go back to
// the See state sequence:
if (!target || target.health <= 0 || Distance3D(target) >= MaxTargetRange)
{
return FindState("See");
}
// Otherwise continue:
return null;
}
Goto Missile+1;
}
}