The oPRState Object

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.

Methods

PRAddState(stateName, stateFunc, validFromStatesOpt)

Description

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.

Parameters
  • stateName String

The name of the state being added.

  • stateFunc Function ID

The function that implements the state being added.

  • validFromStatesOpt String Array - OPTIONAL

Array of state names that are valid FROM states.

Returns

Nothing

PRCanSetState(stateName)

Description

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.

Parameters
  • stateName String

The name of the state to test.

Returns
Bool

True if the given state can be set. False, otherwise.

PRGetCurrentState()

Description

Returns the name of the object's current state. Returns noone if the object currently has no state.

Parameters
  • None
Returns
String

The current state's name, or noone if the object has no current state.

PRGetCurrentStateFunction()

Description

Returns the function of the object's current state. Returns noone if the object currently has no state.

Parameters
  • None
Returns
Function ID

The current state's function ID, or noone if the object has no current state.

PRGetCurrentStateInfo()

Description

Returns a string containing information about the object's current and previous states.

Parameters
  • None
Returns
String

The current state's function ID, or noone if the object has no current state.

PRGetPreviousState()

Description

Returns the name of the object's previous state. Returns noone if there was no previous state.

Parameters
  • None
Returns
String

The previous state's name, or noone if the object has no previous state.

PRGetStateDate1()

Description

Returns the state object's data 1 value.

Parameters
  • None
Returns
Any

The state's internal data 1 value, or noone if no value assigned.

PRGetStateData2()

Description

Returns the state object's data 2 value.

Parameters
  • None
Returns
Any

The state's internal data 2 value, or noone if no value assigned.

PRGetStateData3()

Description

Returns the state object's data 3 value.

Parameters
  • None
Returns
Any

The state's internal data 3 value, or noone if no value assigned.

PRSetPreviousState(data1Opt, data2Opt, data3Opt)

Description

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.

Parameters
  • data1Opt Any - OPTIONAL

A value to store within the state as data 1. Can be used for any purpose.

  • data2Opt Any - OPTIONAL

A value to store within the state as data 2. Can be used for any purpose.

  • data3Opt Any - OPTIONAL

A value to store within the state as data 3. Can be used for any purpose.

Returns
Bool

True if the previous state was set. False, otherwise.

PRSetState(stateName, data1Opt, data2Opt, data3Opt)

Description

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.

Parameters
  • stateName String

The name of the state to set. Send empty string or noone to set no state.

  • data1Opt Any - OPTIONAL

A value to store within the state as data 1. Can be used for any purpose.

  • data2Opt Any - OPTIONAL

A value to store within the state as data 2. Can be used for any purpose.

  • data3Opt Any - OPTIONAL

A value to store within the state as data 3. Can be used for any purpose.

Returns
Bool

True if the given state was set. False, otherwise.

PRSetStateVerbose(verboseActive)

Description

Turns on/off state change debug messages.

Parameters
  • verboseActive Bool

True to turn on wordy debug messages during state changes. False to turn them off.

Returns

Nothing

Constants

PRSTATE_MODE_END

Description

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

Description

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

Description

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.


© 2021 Prismatic Realms, Inc. Contact

Green Hosting Badge