FindStateByString
Jump to navigation
Jump to search
Note: This feature is for ZScript only. |
clearscope native state FindStateByString(string st, bool exact = false)
Usage
Functions like FindState, except that it accepts a text string data type as the state to search for, instead of directly having to use a StateLabel type. The main use case is for dynamically creating states to jump to using the built-in String functions.
Note: just like FindState, must be prefixed with invoker.
if called in PSprite context (i.e. from a Weapon state or action function), otherwise it won't know which actor's state (the weapon's or the owner's) must be found.
Parameters
- string st
- The string containing 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 actor changes to 5 random states by just stitching a number from 1 to 5 at the end of a string, and passing it to FindStateByString(), instead of having to use a Switch/Case.
//This actor jumps to random states using a randomized state string.
class RandomStringStateJumper : Actor
{
States
{
Spawn:
TNT1 A 0 NoDelay
{
//Decide a random graphic to show with RNG, then append that as the Graphic# state to go to.
String pickState = String.Format ("Graphic%d", random(1,5));
return FindStateByString (pickState);
}
Stop;
Graphic1:
PLAY A -1;
Stop;
Graphic2:
POSS A -1;
Stop;
Graphic3:
TRE2 A -1;
Stop;
Graphic4:
TLMP A -1;
Stop;
Graphic5:
SMT2 A -1;
Stop;
}
}