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);

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.

  • I'm not sure what you mean. The FSM does have memory. See my edit for a bit of explanation. 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. Apr 29 '11 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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