SetState

From ZDoom Wiki
Jump to navigation Jump to search

Actor

native bool SetState(state st, bool nofunction = false)

Usage

Forcefully sets the calling actor's State to the specified state sequence. Same as SetStateLabel, except the first argument is a State pointer, which must first be obtained with FindState or ResolveState.

Note: This is NOT a state jump function, and it should not be called from inside a state/anonymous function. It's meant to be called from outside of states. For state jumps, use return FindState("<State label>") in actors, or return ResolveState("<State label>") in weapons.

Parameters

  • state st
A State pointer obtained with FindState or ResolveState.
  • bool nofunction
Does nothing. (Verification needed)

Return values

Returns true if the state was successfully modified.

Examples

This version of Doom Imp's fireball after existing for 10 tics will move from Spawn state sequence to the Plasma state sequence, which makes it look like the PlasmaBall:

class FakePlasmaBall : DoomImpBall
{
	override void Tick()
	{
		super.Tick();
		// Check if age is above 10 tics and the actor is currently
		// in its spawn state sequence:
		if (GetAge() > 10 && InStateSequence(curstate, spawnstate))
		{
			SetState(FindState("Plasma"));
		}
	}

	States 
	{
	Plasma:
		PLSS AB 5 bright;
		loop;
	}
}

Used in the example:

Note: spawnstate is an Actor field that contains a pointer to the first state in their Spawn state sequence. It's the same as FindState("Spawn").

See also