O'Reilly logo

Learning Game AI Programming with Lua by David Young

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Finite state machines

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

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required