I'm following Mat Buckland's Programming Game AI by Example, and I find that I don't always have use for enter(), execute() and exit() on an entity's state. For example, in an RPG, a weapon may have an equipped state, and I may use enter() and exit() for that state to add or subtract to a player's ability modifier, but there isn't really a need for execute(). Is this a design flaw in my engine, or a shortcoming of this approach?


2 Answers 2


Not having read the book, those calls sound like normal entry points for a state machine. To understand the calls, let's look at what they do.

enter() - executed when the state is activated.

execute() - executed while the state is activated.

exit() - executed when the state is deactivated.

These fit any kind of state machine. Some machines only need the 'execute' calls, others need the 'enter' and 'exit', and still others need all the three.

Example 1: Machine gun trigger.

  • Execute: fire bullets at set rate.

Example 2: Force bridge

  • Enter: make bridge appear
  • Exit: make bridge disappear

Example 3: Personal power armor.

  • Enter: give player extra protection
  • Execute: drain batteries
  • Exit: remove extra protection

It's not necessarily a sign of any flaw. Not every entity or state will have a use for every available method. Just leaving the execute() method empty would be fine, IMO.


You must log in to answer this question.