State
This was deprecated in v1.0.0
One named state of a StateManager. Create one with
StateManager.newState(name) (or require a ModuleScript that returns one, see
LoadStates), attach callbacks with OnEnter / OnExit, and
pass it in the States list of StateManager.new. You can also get one back from
StateManager:GetState.
A State owns a Trove that is cleaned each time the state is exited, so use it for anything
that should only live while the state is active.
local Round = StateManager.newState("Round")
Round:OnEnter(function(manager, trove, lastState)
local timer = trove:Add(Instance.new("Sound")) -- destroyed on exit
end)
This package is no longer maintained; see the deprecation notice on StateManager.
Properties
Name
This item is read only and cannot be modified. Read OnlyState.Name: stringThe name given to newState. StateManager:GetState and ChangeState look states up by it.
Entered
This item is read only and cannot be modified. Read OnlyFires (deferred) after this state becomes current. Receives the StateManager, this state's Trove and the previous state's name (or nil). OnEnter connects to it.
Exited
This item is read only and cannot be modified. Read OnlyState.Exited: Signal<>Fires with no arguments right after this state is exited and its Trove has been cleaned. OnExit connects to it.
Trove
State.Trove: TroveCleaned every time the state is exited (and when the StateManager is destroyed). The same Trove is passed to OnEnter callbacks.
Functions
OnEnter
State:OnEnter(func: (trove: Trove,lastState: string?) → ()--
Called each time the state is entered.
) → Connection--
The signal connection; disconnect it to stop listening.
Connects func to this state's Entered signal. It runs (deferred with task.defer, after
StateManager.StateChanged has fired) every time the state becomes current, receiving:
stateManager- the StateManager that switched to this state;-
trove- this state'sTrove, cleaned when the state is exited; connect and create everything state-specific through it; lastState- the name of the state that was current before, ornilif there was none.
OnExit
State:OnExit(func: () → ()--
Called each time the state is exited.
) → Connection--
The signal connection; disconnect it to stop listening.
Connects func to this state's Exited signal. It runs synchronously, with no arguments,
every time the state stops being current (from ChangeState or ExitCurrent), after the
state's Trove has already been cleaned.