The oPRState object included in the PRState package is an object that implements the finite state machine. The objects in your project that require states must define the oPRState object as their parent object. Once that is done, your objects will inherit the finite state machine system and the methods below.
PRAddState(stateName, stateFunc, validFromStatesOpt)
Adds a new state to the object. The function you provide for stateFunc, which must receive 1 parameter representing the call mode, should contain all of your state implementation code. validFromStatesOpt is an optional array of strings which define a list of valid states that the state being added can transition from without restriction. Ignore this parameter if the state being added has no such restrictions.
The name of the state being added.
The function that implements the state being added.
Array of state names that are valid FROM states.
Nothing
PRCanSetState(stateName)
Returns a boolean indicating whether or not the state in stateName can be set from the object's current state. The given state's list of valid from states is consulted. If the object's current state is found in that list, or if the list is empty, then true is returned otherwise false is returned. False is also returned if the given stateName is unrecognized. True is returned if stateName is an empty string or noone, indicating no state.
The name of the state to test.
True if the given state can be set. False, otherwise.
PRGetCurrentState()
Returns the name of the object's current state. Returns noone if the object currently has no state.
The current state's name, or noone if the object has no current state.
PRGetCurrentStateFunction()
Returns the function of the object's current state. Returns noone if the object currently has no state.
The current state's function ID, or noone if the object has no current state.
PRGetCurrentStateInfo()
Returns a string containing information about the object's current and previous states.
The current state's function ID, or noone if the object has no current state.
PRGetPreviousState()
Returns the name of the object's previous state. Returns noone if there was no previous state.
The previous state's name, or noone if the object has no previous state.
PRGetStateDate1()
Returns the state object's data 1 value.
The state's internal data 1 value, or noone if no value assigned.
PRGetStateData2()
Returns the state object's data 2 value.
The state's internal data 2 value, or noone if no value assigned.
PRGetStateData3()
Returns the state object's data 3 value.
The state's internal data 3 value, or noone if no value assigned.
PRSetPreviousState(data1Opt, data2Opt, data3Opt)
	Set the object's state and data properties to what they were prior to the current state. You can optionally provide up to 3 new pieces of data of any type, which can be queried from within your state's implementation function for any purpose as desired. If you don't specify any of these values, the original 3 values from the previous state will be used.
A value to store within the state as data 1. Can be used for any purpose.
A value to store within the state as data 2. Can be used for any purpose.
A value to store within the state as data 3. Can be used for any purpose.
True if the previous state was set. False, otherwise.
PRSetState(stateName, data1Opt, data2Opt, data3Opt)
Set the object's current state to the state with the given stateName. Pass a blank string for stateName (or noone) to set the object to no state. Checks first to see if the new state is valid (see PRCanSetState function). You can optionally provide up to 3 pieces of data of any type, which can be queried from within your state's implementation function for any purpose as desired. Setting a valid state will call the previous state's implementation function in "end" mode and the new state's implementation function in "init" mode, which are appropriate times to call your de-initialization and initialization code respectively. Note that setting the state to no state (stateName is an empty string or noone) is always allowed, regardless of the state's valid from states list.
The name of the state to set. Send empty string or noone to set no state.
A value to store within the state as data 1. Can be used for any purpose.
A value to store within the state as data 2. Can be used for any purpose.
A value to store within the state as data 3. Can be used for any purpose.
True if the given state was set. False, otherwise.
PRSetStateVerbose(verboseActive)
Turns on/off state change debug messages.
True to turn on wordy debug messages during state changes. False to turn them off.
Nothing
PRSTATE_MODE_END
Specifies the cleanup/destruction mode of a state implementation method or function. Supplied as a parameter to the method/function when it is called. Use as an indication that it is the proper moment to run your state clean-up/destruction code.
PRSTATE_MODE_INIT
Specifies the initialization mode of a state implementation method or function. Supplied as a parameter to the method/function when it is called. Use as an indication that it is the proper moment to run your state initialization code.
PRSTATE_MODE_UPDATE
Specifies the frame update mode of a state implementation method or function. Supplied as a parameter to the method/function when it is called. Use as an indication that it is the proper moment to run your core state implementation code.