Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 9 down vote accepted

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
share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.