Machinejs
Make behaviour trees in JavaScript
Install / Use
/learn @maryrosecook/MachinejsREADME
#Machine.js Make behaviour trees in JavaScript
v1.1 [see changelog]
By mary rose cook
- http://maryrosecook.com
- maryrosecook@maryrosecook.com
##What is Machine.js?
Machine.js lets you use a hierarchical state machine to control a JavaScript object.
-
Define a behaviour tree as JSON.
<pre><code>{ identifier: "idle", strategy: "prioritised", children: [ { identifier: "photosynthesise", strategy: "sequential", children: [ { identifier: "makeEnergy" }, { identifier: "grow" }, { identifier: "emitOxygen" }, ] }, { identifier: "gatherSun" }, { identifier: "gatherWater" }, ] }; </code></pre> -
For each leaf state, define a function that enacts the behaviour for that state. So, for the gatherSun state, define a function that gathers sun.
-
For each state, define a can function that returns true if the actor may move to that state. So, for the gatherSun state, define a function canGatherSun that returns true if the sun is out.
##Licence
The code is open source, under the MIT licence. It uses Base.js by Dean Edwards.
##Getting started
Download the repository. Open index.html in your browser to see the demo and documentation.
Related Skills
node-connect
340.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
340.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.2kCommit, push, and open a PR
