dropecho.fsm

A finite state machine implementation.
https://github.com/dropecho/fsm/

To install, run:

haxelib install dropecho.fsm 0.2.1 

See using Haxelib in Haxelib documentation for more information.

README.md

FSM - A finite state machine implementation.

Usage

js

var {FSM, State} = require("dropecho.fsm");

var entity = {
  data: 0
};

// input function is state "action", called when state is run.
var testState1 = new State(entity => {
  entity.data += 1;
  console.log("state1");
});

var testState2 = new State(entity => {
  entity.state2Ran = true;
  console.log("state2");
})

testState1.transitions.push(entity => {
  if (entity.data >= 2) {
    return testState2;
  }

  // null means don't transition
  return null;
});

st2.transitions.push(entity -> {
  if (entity.state2Ran) {
    return st1;
  }

  return null;
});

var fsm = new FSM(testState1);

fsm.run(); // state1
fsm.run(); // state1
fsm.run(); // state2
fsm.run(); // state1
fsm.run(); // state2
fsm.run(); // state1
fsm.run(); // state2
Contributors
vantreeseba
Version
0.2.1
Published
6 years ago
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub

⌂