Reader small image

You're reading from  Learning Game AI Programming with Lua

Product typeBook
Published inNov 2014
Reading LevelBeginner
PublisherPackt
ISBN-139781783281336
Edition1st Edition
Languages
Right arrow
Author (1)
David Young
David Young
Right arrow

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 data members.
    state.name_ = name;
    state.action_ = action;
    
    return state;
end

Transitions

Transitions encapsulate the state to be transitioned to as well as the evaluator that determines whether the transition should...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Learning Game AI Programming with Lua
Published in: Nov 2014Publisher: PacktISBN-13: 9781783281336

Author (1)