Class Index | File Index

Classes


Class stateControl


Extends component.
stateControl
Defined in: stateControl.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
Adds a state machine mechanism to the entity.
Field Summary
Field Attributes Field Name and Description
 
Returns whether or not the machine is in a halted state.
 
Returns the current state tag.
Fields borrowed from class component:
host, info, isDrawing, isStepping, onAttach, onDraw, onStep, tag
Method Summary
Method Attributes Method Name and Description
 
createState(name, onInit, onStep, onDraw)
Sets this array of functions as the only one associated with the state of the given name.
 
execute(name)
Begins the state machine execution loop from the given state.
 
halt()
stops all current execution.
 
Removes the state.
Methods borrowed from class component:
canHandleEvent, draw, emitEvent, getKnownEvents, installEvent, installHandler, installHook, step, uninstallEvent, uninstallHandler, uninstallHook
Class Detail
stateControl()
Adds a state machine mechanism to the entity. Each StateControl instance is effectively a dynamic state machine. After desgnating what states exist within the machine using CreateState(), the machine can be run using Execute(). Using each state's StepFunc, the states will transition until an invalid state is returned. Referring to an invalid state halts the state machine. It is also entirely valid to modify the state machine mid-execution.
Field Detail
halted
Returns whether or not the machine is in a halted state.

state
Returns the current state tag. If no execution state is active, the empty string is returned.
Method Detail
createState(name, onInit, onStep, onDraw)
Sets this array of functions as the only one associated with the state of the given name. During each state, different logic is disgnated to run to control what happens during this state and when the state should be altered. The step function of the state loop is is meant to hold the bulk of the logic, but it also returns what state should be transitioned to. If the state is to be kept the same, the StepFunc should simply return the empty string. The draw function of the array can be used to produce visual effects associated with the state, but may not change the current state. If the state tag returned by the StepFunc does not refer to a valid state part of stateControl, the execution state of the stateControl halts. After being halted, the state machine will remain idle until the next execute() is called.
Parameters:
{String} name
Name of the state.
{Function} onInit
The function to call when entering a state
{Function} onStep
The function to call during the step phase of the component when in this state
{Function} onDraw
The function to call during the draw phase of the component when in this state

execute(name)
Begins the state machine execution loop from the given state. If begin state does not refer to a valid state, no action is taken. If done in the middle of a state loop function, any queued function calls are cancelled.
Parameters:
{String} name

halt()
stops all current execution. If done during a state loop, all remaining state loop functions that would have executed are cancelled.

removeState(name)
Removes the state. No action is taken if the tag does not refer to a valid state.
Parameters:
{String} name

Documentation generated by JsDoc Toolkit 2.4.0 on Sun Feb 03 2019 18:30:57 GMT-0500 (EST)