Creating a finite state machine (FSM) for modeling logic will resemble the animation state machines we've created previously, except that transitioning to a new state within the state machine is handled automatically through the evaluation of transitions. Once one evaluator returns true, the state machine will transition to the new state and invoke the associated state's action.
States within an FSM are responsible for associating an action with the state. We create a state by passing an action and naming the state for debug convenience:
FiniteState.lua
:
require "Action"; require "FiniteState"; require "FiniteStateTransition"; FiniteState = {}; function FiniteState.new(name, action) local state = {}; -- The FiniteState's data members. state.name_ = name; state.action_ = action; return state; end