state — Luau Binding
require("state"): attach a state machine to a target — states that play animations, transitions on inputs, events, and timers. The programmatic surface of the state system. Every function is[antos].
Status: design. Not built yet.
local state = require("state")
| Call | Returns | Does |
|---|---|---|
state.machine(target) |
sm |
attach a machine to target |
sm:state(name, defs) |
sm |
define a state — defs = { enter, update, exit }; enter usually starts a motion / tween |
sm:on(from, when, to) |
sm |
a transition — when is a condition fn, an input action, a timer, or an event name |
sm:set(name) |
ok |
force the active state (fires its enter) |
sm:current() |
name |
the active state |
local state = require("state")
local sm = state.machine(hero)
:state("idle", { enter = function() motion.stop(hero) end })
:state("walk", { enter = function() motion.play(hero, walk$, { loop = true }) end })
:on("idle", input.action("moveX"), "walk")
:on("walk", function() return input.axis("moveX") == 0 end, "idle")