Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Say you're building an FSM for something like a game and you've got states like:

  • MainMenu
  • Options
  • SinglePlayer
  • MultiPlayer

Your state diagram might look something like this:

enter image description here

Now say you have a shared state, DevConsole, (shows the console when tilde is pressed and receives KB input etc. I'm sure you've seen it before) such that no matter what state you're in, this state applies.

How do you diagram that?


An example of how it would function would be like this:

public class StateMachine
    protected State sharedState;
    protected State previousState;
    protected State currentState;

    public void Update()

        if (this.previousState != null && this.previousState.IsExiting)

    // called by individual states
    public void ChangeState<StateType>()
        // creates a new state adn sets its state machine owner to this machine
        this.previousState = this.currentState;
        this.currentState = StateBuilder.Build<StateType>(this);
share|improve this question
really? 7 out of 36 questions accepted? i was intrigued by the question but won't be putting any more effort into it than typing this comment.. – Demian Brecht Apr 29 '11 at 3:46
What's wrong with two diagrams? – S.Lott Apr 29 '11 at 10:54
@Demian Brecht: Fair enough. There's some questions I've asked that could have accepted answers. I went through and accepted a few. Generally, however this is not an issue on See here:… and here:… – Steve Evers Apr 29 '11 at 12:49
Are you looking for a hierarchical state diagram? – Martin Wickman Apr 29 '11 at 16:47
@Martin Wickman: Interesting. I'll have to take a closer look at that. Thanks. – Steve Evers Apr 29 '11 at 17:05
up vote 1 down vote accepted

Since your FSM does not have memory, for the CONSOLE state you would actually need a different "version" for every other state, otherwise there would be no way to determine to which state to return when you close the console.

You would be able to accomplish this with any automata that does have memory, like a Pushdown Automata.

share|improve this answer
I'm not sure what you mean. The FSM does have memory. See my edit for a bit of explanation. – Steve Evers Apr 29 '11 at 16:10
@SnOrfus - In that case, you can make it a non-deterministic FSM, and simple have one state called CONSOLE, with each state transisting to it, and then CONSOLE transisting to every other state on whatever key closes the console. NFA can have multiple transitions on the same symbol. – Nico Huysamen Apr 29 '11 at 16:17

Your Answer


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.