State
A state a Machine can be in. Created with Felix.State.new(name).
local jump = Felix.State.new("Jump")
jump.OnEnter = function(machine)
print("Jumping!")
end
Properties
Name
State.Name: stringThe state's name. Transitions target states by this name, so it must be unique within a machine.
Transitions
The transitions that can leave this state, checked in order when a trigger is sent. Add to it with table.insert.
OnEnter
State.OnEnter: Callback?Called with the machine and any event data when the machine enters this state.
OnExit
State.OnExit: Callback?Called with the machine and any event data when the machine leaves this state.
OnUpdate
State.OnUpdate: UpdateCallback?
Called with the machine and dt on every Machine:Update while the machine is in this state (or in one of
its children). Parents run before children.
Parent
State.Parent: string?The name of this state's parent, for hierarchical machines. While a child is active its parents are too: Machine:Is matches them, their transitions, State.Tags and State.Resistance apply, and they're only exited when a transition leaves them.
local combat = Felix.State.new("Combat")
local light = Felix.State.new("Light")
light.Parent = "Combat"
Initial
State.Initial: string?The child entered automatically when this state is entered, so a transition can target a parent.
Duration
State.Duration: number?Seconds of machine time after which the machine moves to State.Next on its own. Driven by Machine:Update. The move ignores Conditions and [State.Resistance]: it's the state ending, not an interrupt.
windup.Duration = 0.15
windup.Next = "Active"
Next
State.Next: string?The state entered when State.Duration runs out. Required when Duration is set.
Resistance
State.Resistance: Resistance?
The minimum Transition.Priority needed to leave this state, or a function returning it. Defaults to the
nearest parent's Resistance, or 0. A function is re-evaluated on every Send, which makes cancel windows easy:
-- Uncancellable for the first 0.25s, then anything goes
heavy.Resistance = function(machine)
return if machine:GetTimeInState() < 0.25 then 10 else 0
end
Timeouts (State.Duration), Machine:ForceState and Machine:Stop ignore it.
Tags
State.Tags: {[string]: any}?Values that describe the state, read with Machine:HasTag and Machine:GetTag. A child's tag overrides its parent's.
dodge.Tags = { Invulnerable = true, CanMove = false }
Functions
new
Trigger
State:Trigger() → Transition?--
The first transition listening for trigger whose Conditions all pass
Finds the transition in this state's own Transitions that a trigger would fire, without running it.
It doesn't look at parents, the machine's AnyTransitions or State.Resistance; use Machine:CanSend for that.