While in development of a character, I feel like I'm digging myself deeper into a hole every time I add more functionality to him, creating more bugs and it seems like my code is tripping over itself all over the place.

What are the best practices when managing character states for a character that has a large selection of abilities and actions that they can perform, without their abilities interrupting each other and creating a mess overall?

  • \$\begingroup\$ I'd start by revising the design; if you're having trouble keeping track of everything with insider knowledge imagine your poor players trying to figure it out =) In my case, when a system starts to feel too complex I take a step back work it out on paper before continuing - not only can I show paper to other people, it forces me to think ahead and justify each piece. Or you could just talk to the rubber duck c2.com/cgi/wiki?RubberDucking \$\endgroup\$ Jun 17, 2012 at 19:20
  • \$\begingroup\$ I would definitely like to revise the design, I just don't know exactly what part of it is broken. The system is simple in design, but the manner I have it implemented seems to be poorly written because my character cancels actions for other actions, which isn't behavior that I find very desirable. \$\endgroup\$ Jun 17, 2012 at 19:26
  • 1
    \$\begingroup\$ I'd suggest fleshing your question out a bit more. What sort of states do you mean? What kind of problems do you encounter? Each game is different so there aren't really any best practices, just potential solutions for potential problems. \$\endgroup\$
    – Kylotan
    Jun 17, 2012 at 19:55
  • \$\begingroup\$ Well, I would imagine this could apply to any character that has multiple abilities, actions, or states that you would like them to be able to execute at any time, however, only with one in use at a time. What is the best practice to keep these abilities separate from overlapping or creating unwanted bugs? \$\endgroup\$ Jun 17, 2012 at 20:29
  • \$\begingroup\$ Like I said, there is no best practice, because every game is different. I'll post a vague answer below but what you're asking is very general. \$\endgroup\$
    – Kylotan
    Jun 17, 2012 at 21:08

1 Answer 1


If a character can only perform one action at a time, then you can use the State pattern to represent that action.

Basically this means that your character contains an object which handles the current state of the character, or specifically in this case, the current action. Typically you derive all your states from a standard base class or interface, which in a game might only have 1 method on it, an Update() function.

Add the action object when the action begins, call Update() once per frame or as often as you need to update the state, and remove the object when the action is complete.

  • \$\begingroup\$ Even with multiple actions he could use multiple state machines, like one for movement, another for attacking etc. \$\endgroup\$
    – Kikaimaru
    Jun 17, 2012 at 21:28
  • \$\begingroup\$ I actually think this is closer to what I'm looking for, especially being as my character is 2D, he's not going to be able to move while attacking at the same time (at least that's the behavior I am aiming for) I will have a look at this, thank you for your input! \$\endgroup\$ Jun 17, 2012 at 22:10
  • \$\begingroup\$ +1 for states. One of the best ways to keep track of objects (in my opinion) in a game environment. \$\endgroup\$ Jun 18, 2012 at 16:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .