Skip to content

Every handler ​

VideState.everyHandler acts on many handlers with one call. It acts on every handler that exists, or on the ones that match a filter. Use it for settings and effects that belong to the whole game, such as a pause menu, a game-wide animation speed, closing every menu, or skipping every animation on screen.

luau
const VideState = require("@VideState")

VideState.everyHandler.scaleSpeed({ speed = 0.5 }) -- slow motion for everything
VideState.everyHandler.pause() -- pause every handler
VideState.everyHandler.finish() -- end every running transition

-- Only some handlers: narrow the scope with filters, and chain as many as you need.
-- This closes every menu that is still open. A menu is a handler whose rule lists "Menu" in its `tags`.
VideState.everyHandler.withTags("Menu").withoutStates("Closed").setState("Closed")

everyHandler and every filtered scope have the same functions, called a group. A group looks its handlers up each time you call a function, so a handler created later is included, and a handler that changed state since the last call is matched by its new state.

Each action calls the handler's own function of the same name, so every handler fires its own events, such as onPause and onFinish. A handler that has been destroyed leaves the list.

If a callback of one handler raises an error, the other handlers still run, and the first error is raised once all of them have run.

Filters ​

A filter returns a new group that is narrower than the one it was called on. Filters are combined with "and": a handler is in scope only when it passes every filter in the chain. Calling a filter does not look anything up yet, so you can keep a group in a variable and use it later.

Each kind of filter has an inclusion and an exclusion: withTags and withoutTags, withRule and withoutRule, and withStates and withoutStates.

Conflicts ​

A chain of filters that no handler could ever pass is a mistake, such as withTags("Menu").withoutTags("Menu"), so a filter checks itself against the filters before it. When it conflicts, the filter raises one error that lists every conflict, and it does so when you build the chain, not when you call an action.

luau
const VideState = require("@VideState")

-- Raises: everyHandler.withoutTags conflicts with an earlier filter: tag "Hud" is required by withTags; tag "Menu" is required by withTags. No handler could match
VideState.everyHandler.withTags("Menu", "Hud").withoutTags("Hud", "Menu")

These are the conflicts:

FilterConflicts when
withTagsA tag is already in withoutTags.
withoutTagsA tag is already in withTags.
withRuleThe rule is already in withoutRule, or withRule already asked for a different rule, because a handler has one rule.
withoutRuleThe rule is already in withRule.
withStatesNone of its states is allowed by an earlier withStates, or every state that is left is in withoutStates.
withoutStatesIt leaves no state that an earlier withStates allows.

Repeating a value, such as withTags("Menu").withTags("Menu"), is not a conflict. A withStates that keeps some of its states, such as withStates("Open", "Closed").withoutStates("Open"), is not one either. VideState compares what you wrote and does not read the tags of a rule you named, so withRule("Panel").withoutTags("Menu") is not checked against the tags that Panel has.

withTags Added in 0.3.0 ​

luau
Group.withTags(
    ...: string -- The tags a rule must have
) -> EveryHandlerGroup

Narrows the scope to the handlers whose rule has all of the given tags. Tags come from the tags of the rule's metadata and are matched exactly as written, as in getAllRulesWithTags.

Parameters

NameTypeDescription
...stringRequired. One or more tags. A rule must have every one of them.

Returns

TypeDescription
EveryHandlerGroupA group that acts on the matching handlers.

Errors

CauseMessage
ErrorNo tag was giveneveryHandler.withTags requires at least one tag
ErrorA tag is not a stringeveryHandler.withTags tag <index> must be a string, got <type>
ErrorA tag is in withoutTagseveryHandler.withTags conflicts with an earlier filter: tag "<tag>" is excluded by withoutTags. No handler could match

withoutTags Added in 0.3.0 ​

luau
Group.withoutTags(
    ...: string -- The tags a rule must not have
) -> EveryHandlerGroup

Narrows the scope to the handlers whose rule has none of the given tags. A handler is left out when its rule has any one of them. Tags are matched exactly as written.

Parameters

NameTypeDescription
...stringRequired. One or more tags. A rule that has any one of them is left out.

Returns

TypeDescription
EveryHandlerGroupA group that acts on the matching handlers.

Errors

CauseMessage
ErrorNo tag was giveneveryHandler.withoutTags requires at least one tag
ErrorA tag is not a stringeveryHandler.withoutTags tag <index> must be a string, got <type>
ErrorA tag is in withTagseveryHandler.withoutTags conflicts with an earlier filter: tag "<tag>" is required by withTags. No handler could match

withRule Added in 0.3.0 ​

luau
Group.withRule(
    ruleName: string -- The name of the rule
) -> EveryHandlerGroup

Narrows the scope to the handlers created from the rule with this name. A name that no rule has matches no handler.

Parameters

NameTypeDescription
ruleNamestringRequired. The name given in the rule's metadata.

Returns

TypeDescription
EveryHandlerGroupA group that acts on the matching handlers.

Errors

CauseMessage
ErrorruleName is not a stringeveryHandler.withRule rule name must be a string, got <type>
ErrorThe rule is in withoutRuleeveryHandler.withRule conflicts with an earlier filter: rule "<rule>" is excluded by withoutRule. No handler could match
ErrorAn earlier withRule asked for another ruleeveryHandler.withRule conflicts with an earlier filter: a handler has one rule, but withRule asks for <rule>, <rule>. No handler could match

withoutRule Added in 0.3.0 ​

luau
Group.withoutRule(
    ruleName: string -- The name of the rule
) -> EveryHandlerGroup

Narrows the scope to the handlers that were not created from the rule with this name. Call it again to leave out more rules.

Parameters

NameTypeDescription
ruleNamestringRequired. The name given in the rule's metadata.

Returns

TypeDescription
EveryHandlerGroupA group that acts on the matching handlers.

Errors

CauseMessage
ErrorruleName is not a stringeveryHandler.withoutRule rule name must be a string, got <type>
ErrorThe rule is in withRuleeveryHandler.withoutRule conflicts with an earlier filter: rule "<rule>" is required by withRule. No handler could match

withStates Added in 0.3.0 ​

luau
Group.withStates(
    ...: string -- The states a handler may be in
) -> EveryHandlerGroup

Narrows the scope to the handlers whose current state is one of the given names. The state is read each time you call a function of the group. A second withStates narrows it further, to the states that both calls allow.

Parameters

NameTypeDescription
...stringRequired. One or more state names. A handler in any one of them stays in scope.

Returns

TypeDescription
EveryHandlerGroupA group that acts on the matching handlers.

Errors

CauseMessage
ErrorNo state name was giveneveryHandler.withStates requires at least one state name
ErrorA state name is not a stringeveryHandler.withStates state name <index> must be a string, got <type>
ErrorNo state is lefteveryHandler.withStates conflicts with an earlier filter: <conflict>. No handler could match

withoutStates Added in 0.3.0 ​

luau
Group.withoutStates(
    ...: string -- The states a handler must not be in
) -> EveryHandlerGroup

Narrows the scope to the handlers whose current state is none of the given names. The state is read each time you call a function of the group.

Parameters

NameTypeDescription
...stringRequired. One or more state names. A handler in any one of them is left out.

Returns

TypeDescription
EveryHandlerGroupA group that acts on the matching handlers.

Errors

CauseMessage
ErrorNo state name was giveneveryHandler.withoutStates requires at least one state name
ErrorA state name is not a stringeveryHandler.withoutStates state name <index> must be a string, got <type>
ErrorIt leaves no state that withStates allowseveryHandler.withoutStates conflicts with an earlier filter: state "<state>" is required by withStates. No handler could match

Actions ​

scaleSpeed Added in 0.3.0 ​

luau
Group.scaleSpeed(
    options: ScaleSpeedOptions -- How much to scale the speed of the handlers in scope
) -> ()

Speeds up or slows down the handlers in scope. It multiplies with the scale of each handler (see the handler's scaleSpeed) and with each connection's own speed, so the speed of a connection is global scale × handler scale × connection speed.

On everyHandler itself, the scale applies by default to the transitions that are running now and to every transition that starts later, including those of handlers created later, until you call scaleSpeed again. A speed of 1 removes it. With once = true it scales only the transitions that are running now: each handler goes back to normal speed at its next setState, and handlers created later are not affected.

On a filtered group, scaleSpeed calls scaleSpeed on each handler in scope. A scale without once then reaches only the handlers that exist now, and it replaces the scale that handler had set itself.

Parameters

NameTypeDescription
optionsScaleSpeedOptionsRequired. The speed scale, and whether it applies once.

Errors

CauseMessage
Erroroptions is not a tableeveryHandler.scaleSpeed options must be a table
Erroroptions has an unknown keyeveryHandler.scaleSpeed options has an unknown key <key>
Erroroptions.speed is not a finite number above 0everyHandler.scaleSpeed speed must be a finite number above 0
Erroroptions.once is not a booleaneveryHandler.scaleSpeed once must be a boolean

pause Added in 0.3.0 ​

luau
Group.pause() -> ()

Calls pause on every handler in scope. It reaches the handlers that exist when you call it, so a handler created while everything is paused is not paused.

resume Added in 0.3.0 ​

luau
Group.resume() -> ()

Calls resume on every handler in scope.

finish Added in 0.3.0 ​

luau
Group.finish() -> ()

Calls finish on every handler in scope: each one sends its last frame before finish returns, and then fires its own onFinish.

setState Added in 0.3.0 Changed in 0.5.0 ​

luau
Group.setState(
    stateName: string, -- The state to change to
    options: EverySetStateOptions? -- The options of the handler's setState, and stagger
) -> ()

Calls setState on every handler in scope.

A rule decides which state names its handlers have, so some handlers in scope can lack stateName. VideState checks all of them first. If any lack it, setState raises one error that lists every rule that is missing the state, with how many of its handlers are in scope, and no handler changes state. Narrow the scope with a filter, such as withRule or withTags, until every handler in it has the state.

luau
const VideState = require("@VideState")

-- Raises: everyHandler.setState state "Closed" is missing in 3 handlers: Dialog (1), Panel (2). No handler changed state
VideState.everyHandler.setState("Closed")

Parameters

NameTypeDescription
stateNamestringRequired. The name of the state.
optionsEverySetStateOptions?Optional. The options of the handler's setState, instant and delay, and stagger.

Errors

CauseMessage
ErrorstateName is not a stringeveryHandler.setState state name must be a string, got <type>
Erroroptions.stagger is not a finite non-negative numbereveryHandler.setState stagger must be a finite non-negative number
ErrorThe rule of one or more handlers does not let them change to the stateeveryHandler.setState cannot change to state "<stateName>" in <count> handlers: <rule> (<handlers>), ... No handler changed state
ErrorOne or more handlers in scope lack the stateeveryHandler.setState state "<stateName>" is missing in <count> handlers: <rule> (<handlers>), ... No handler changed state

An invalid options raises the errors of the handler's setState.

destroy Added in 0.3.0 ​

luau
Group.destroy() -> ()

Calls destroy on every handler in scope. Each one stops its transitions silently, removes its listeners, and raises an error on its next setState. A destroyed handler leaves the list of handlers, so a later call skips it.

On everyHandler itself this ends every handler in the game, so use it when you tear everything down, such as when a test ends. To destroy only some handlers, use a filter.

Queries ​

count Added in 0.3.0 ​

luau
Group.count() -> number

Returns

TypeDescription
numberHow many handlers are in scope.

isAnyRunning Added in 0.3.0 ​

luau
Group.isAnyRunning() -> boolean

Returns

TypeDescription
booleantrue when at least one handler in scope has a running transition. false when none does, and when the scope is empty.

isAnyPaused Added in 0.3.0 ​

luau
Group.isAnyPaused() -> boolean

Returns

TypeDescription
booleantrue when at least one handler in scope is paused. false when none is, and when the scope is empty.

Types ​

EveryHandlerGroup Added in 0.3.0 Changed in 0.5.0 ​

luau
type EveryHandlerGroup = {
    withTags: (...string) -> EveryHandlerGroup, -- Keeps the handlers whose rule has all of the tags
    withoutTags: (...string) -> EveryHandlerGroup, -- Drops the handlers whose rule has any of the tags
    withRule: (ruleName: string) -> EveryHandlerGroup, -- Keeps the handlers of one rule
    withoutRule: (ruleName: string) -> EveryHandlerGroup, -- Drops the handlers of one rule
    withStates: (...string) -> EveryHandlerGroup, -- Keeps the handlers in any of the states
    withoutStates: (...string) -> EveryHandlerGroup, -- Drops the handlers in any of the states
    scaleSpeed: (options: ScaleSpeedOptions) -> (), -- Scales the speed of the handlers in scope
    pause: () -> (), -- Pauses the handlers in scope
    resume: () -> (), -- Resumes the handlers in scope
    finish: () -> (), -- Finishes the transitions of the handlers in scope
    setState: (stateName: string, options: EverySetStateOptions?) -> (), -- Changes the state of the handlers in scope
    destroy: () -> (), -- Destroys the handlers in scope
    count: () -> number, -- How many handlers are in scope
    isAnyRunning: () -> boolean, -- Whether any handler in scope has a running transition
    isAnyPaused: () -> boolean, -- Whether any handler in scope is paused
}

The functions of everyHandler, and of every group that a filter returns. Each one is described above.

EverySetStateOptions Added in 0.5.0 ​

luau
type EverySetStateOptions = {
    instant: boolean?, -- Skips the animation of this change
    delay: number?, -- Seconds every connection waits before it starts
    stagger: number?, -- Seconds between the handlers, in the order they were created
}

The options of setState.

FieldTypeRequiredDefaultDescription
instantbooleanNofalseThe same as in the handler's SetStateOptions.
delaynumberNo0The same as in the handler's SetStateOptions, for every handler.
staggernumberNo0Seconds between the handlers, in the order they were created. The first waits 0, the second stagger, the third twice that, and so on, added to delay. Must be finite and non-negative. See Staggering handlers.