Skip to main content

Transition

A move from one State to another, fired by a trigger. Insert it into the Transitions list of the state it leaves.

table.insert(locked.Transitions, Felix.Transition.new({
	From = "Locked",
	Target = "Open",
	Triggers = { "Unlock" },
	Conditions = { function(machine) return machine.Context.HasKey end },
	Effects = { function(machine) playSound("Click") end },
}))

Properties​

From​

Transition.From: string

The state this transition leaves. It must match the state whose Transitions list it's in (Machine:Start checks), or be "*" for transitions in Machine.AnyTransitions.

Target​

Transition.Target: string

The name of the state to enter.

Triggers​

Transition.Triggers: {string}

The trigger names that fire this transition.

Conditions​

Transition.Conditions: {Condition}

Guards. All must return true for the transition to fire.

Effects​

Transition.Effects: {Effect}

Actions, run in order after the old state exits and before the new state enters.

Priority​

Transition.Priority: number?

How hard this transition interrupts. It only fires if Priority is at least the current state's State.Resistance. Defaults to 0. Use math.huge for transitions nothing should block, like dying.

Except​

Transition.Except: {string}?

For transitions in [Machine.AnyTransitions]: states it doesn't fire from. A state's children are excluded too.

Functions​

new​

Transition.new(params: {
From: string,
Target: string,
Triggers: {string},
Conditions: {Condition}?,
Effects: {Effect}?,
Priority: number?,
Except: {string}?
}) → Transition
Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "",
            "params": [
                {
                    "name": "params",
                    "desc": "",
                    "lua_type": "{ From: string, Target: string, Triggers: { string }, Conditions: { Condition }?, Effects: { Effect }?, Priority: number?, Except: { string }? }"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Transition"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 73,
                "path": "src/transition.luau"
            }
        }
    ],
    "properties": [
        {
            "name": "From",
            "desc": "The state this transition leaves. It must match the state whose `Transitions` list it's in ([Machine:Start]\nchecks), or be `\"*\"` for transitions in [Machine.AnyTransitions].",
            "lua_type": "string",
            "source": {
                "line": 27,
                "path": "src/transition.luau"
            }
        },
        {
            "name": "Target",
            "desc": "The name of the state to enter.",
            "lua_type": "string",
            "source": {
                "line": 33,
                "path": "src/transition.luau"
            }
        },
        {
            "name": "Triggers",
            "desc": "The trigger names that fire this transition.",
            "lua_type": "{ string }",
            "source": {
                "line": 39,
                "path": "src/transition.luau"
            }
        },
        {
            "name": "Conditions",
            "desc": "Guards. All must return `true` for the transition to fire.",
            "lua_type": "{ Condition }",
            "source": {
                "line": 45,
                "path": "src/transition.luau"
            }
        },
        {
            "name": "Effects",
            "desc": "Actions, run in order after the old state exits and before the new state enters.",
            "lua_type": "{ Effect }",
            "source": {
                "line": 51,
                "path": "src/transition.luau"
            }
        },
        {
            "name": "Priority",
            "desc": "How hard this transition interrupts. It only fires if `Priority` is at least the current state's\n[State.Resistance]. Defaults to `0`. Use `math.huge` for transitions nothing should block, like dying.",
            "lua_type": "number?",
            "source": {
                "line": 58,
                "path": "src/transition.luau"
            }
        },
        {
            "name": "Except",
            "desc": "For transitions in [Machine.AnyTransitions]: states it doesn't fire from. A state's children are excluded too.",
            "lua_type": "{ string }?",
            "source": {
                "line": 64,
                "path": "src/transition.luau"
            }
        }
    ],
    "types": [],
    "name": "Transition",
    "desc": "A move from one [State] to another, fired by a trigger. Insert it into the `Transitions` list of the state it leaves.\n\n```lua\ntable.insert(locked.Transitions, Felix.Transition.new({\n\tFrom = \"Locked\",\n\tTarget = \"Open\",\n\tTriggers = { \"Unlock\" },\n\tConditions = { function(machine) return machine.Context.HasKey end },\n\tEffects = { function(machine) playSound(\"Click\") end },\n}))\n```",
    "source": {
        "line": 20,
        "path": "src/transition.luau"
    }
}