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

README.asciidoc

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

Usage:

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:

game.transitionTo(someState);

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

game.getCurrentState();

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

if(game.isInState(someState){
 // do something
}