Simple Finite State Machine library for Processing
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Processing FSM

A simple Finite State Machine library for Processing. Based on the AlphaBeta FSM library for Arduino (matches that API as closely as possible (with the exception of using string names for functions instead of function pointers since function pointers are not available in Java).)


Declare one FSM object and as many State objects as you like.

To initialize a State you need to pass in three strings representing the names of three functions you’ve implemented in your sketch. These functions will be called when the state goes through its transitions:

State playMode = new State(this, "enterPlayMode", "doPlayMode", "exitPlayMode");
  • The first function will be called once each time the FSM enters this state. (enter function)

  • The second function will be called repeated as long as the FSM stays in this state. (execute function)

  • The third function will be called one when the FSM transition away from this state. (exit function)

When you initialize the FSM object, you pass it the state you’d like it to begin in:

FSM game;

game = new FSM(startMode);

In draw(), call the game’s update() function. This will ensure that the library calls the appropriate state’s execute function.

To transition to a different state, call:


To retrieve the state the FSM is currently in, call:


To test if the game is in a current state, call:

 // do something