Note: This PRState documentation is out-dated and is for an older (pre-GMS v2.3) version of PRState. For the most up-to-date docs on the latest version of PRState, please refer to this page as well as the documentation included in the PRState package.

Documentation Topics
Article

Restricting States From Other States

For objects with particularly complex states (or just to add code readability) you may want to declare that a state can only be set if the state being switched from is among a set of valid states. For example, you may want your soldier object to fire his weapon only if he is standing or crouching, but not when he is jumping or climbing. To do this, list the valid states to switch from in an array in the PRStateAdd() function:

PRStateAdd(self, “Stand”, soldierStandState, [“Crouch”, “Jump”]); // Only allow Stand state from Crouch and Jump states.
PRStateAdd(self, “Crouch”, soldierCrouchState, [“Stand”]);  // Only allow Crouch state from Stand state.
PRStateAdd(self, “Climb”, soldierClimbState, [“Stand”]);  // Only allow Climb state from Stand state.
PRStateAdd(self, “Jump”, soldierJumpState, [“Stand”]);  // Only allow Jump state from Stand state.
PRStateAdd(self, “Shoot”, soldierShootState, [“Stand”, “Crouch”]]);  // Only allow Shoot from Stand & Crouch states.

With the above states added to an object, issuing the following command would yield nothing:

// Assuming the current state is “Climb”
PRStateSet(self, “Shoot”);  // Nothing happens.

Restricting states is a great way to prevent some really bizarre situations from occurring. It also helps visualize an object’s abilities and state paths, which is a great help when coding your state scripts.