Debug view
Debugging only
VideState.debug exists to inspect handlers while you develop. Do not use it to drive game logic.
The debug tools show what your handlers are doing: their state, whether a transition is running or paused, and how many onTransition connections they have. Tracking is opt-in, so a handler only shows up after you pass it to track.
const Vide = require("@packages/Vide")
const VideState = require("@VideState")
const schemas = VideState.schemas
const rules = VideState.rules
const PanelRule = rules.dynamic(schemas.new({
visible = schemas.boolean(),
}), { name = "Panel" })
-- `panel` is a handler made from the rule, one for each panel on screen.
const panel = PanelRule.new({
Idle = { visible = Vide.source(false) },
Active = { visible = Vide.source(true) },
}, "Idle")
-- List it in the debug view as "Main panel". Call `untrack()` to remove it again.
const untrack = VideState.debug.track(panel, "Main panel")view shows the tracked handlers in a list that refreshes while it exists. Mount it in a UI Labs story, or in a debug screen in your game. The repository has a story in stories/DebugView.story.luau that you can copy.
Functions
track Added in 0.2.0
VideState.debug.track(
handler: Handler<T>, -- The handler to list
label: string? -- The name to list it under
) -> DisconnectLists a handler in list and the view, under label or the name of its rule. Tracking a handler again changes its label. A tracked handler stays listed until you call the returned function, or until it is destroyed.
Parameters
| Name | Type | Description |
|---|---|---|
handler | Handler<T> | A handler created by a rule. |
label | string? | Optional. The name to list it under. Defaults to the rule name. |
Returns
| Type | Description |
|---|---|
Disconnect | Call it to stop listing the handler. |
Errors
| Cause | Message | |
|---|---|---|
| Error | handler is not a handler | debug.track expects a handler |
| Error | label is not a string | debug.track label must be a string |
snapshot Added in 0.2.0
VideState.debug.snapshot(
handler: Handler<T> -- The handler to read
) -> DebugSnapshotReads what a handler looks like right now, whether or not it is tracked.
Parameters
| Name | Type | Description |
|---|---|---|
handler | Handler<T> | A handler created by a rule. |
Returns
| Type | Description |
|---|---|
DebugSnapshot | The handler's state at this moment. |
Errors
| Cause | Message | |
|---|---|---|
| Error | handler is not a handler | debug.snapshot expects a handler |
list Added in 0.2.0
VideState.debug.list() -> { DebugSnapshot }Reads every tracked handler, in the order they were first tracked. Destroyed handlers are left out and stop being tracked.
Returns
| Type | Description |
|---|---|
{ DebugSnapshot } | One snapshot per tracked handler. |
view Added in 0.2.0
VideState.debug.view() -> FrameCreates a Vide component that lists the tracked handlers, one line each, such as Main panel Active running 0.42 s 2 connections. It refreshes ten times a second while it exists. Call it inside a Vide scope, such as Vide.mount, Vide.root, or a UI Labs story, so its refresh stops when the scope is destroyed.
Returns
| Type | Description |
|---|---|
Frame | The list, sized to fill its parent. |
setFallbackWarnings Added in 0.6.0
VideState.debug.setFallbackWarnings(enabled: boolean)Turns a warning on or off for a tween setting source that returns an invalid value. A transition keeps running when that happens, with "linear" for easing, 0.25 for duration, 0 for delay, and normal speed (or 0 for a negative one) for speed, so a typo can go unnoticed. With the warning on, each stretch of invalid values warns once per source, not every frame. It is off by default.
| Cause | Message | |
|---|---|---|
| Error | enabled is not a boolean | debug.setFallbackWarnings expects a boolean, got <type> |
isFallbackWarnings Added in 0.6.0
VideState.debug.isFallbackWarnings(): booleanReturns whether the fallback warnings are on.
Types
DebugSnapshot Added in 0.2.0
type DebugSnapshot = {
label: string, -- The label passed to track, or the rule name
rule: string, -- The name of the rule that created the handler
state: string, -- The active state
connections: number, -- How many onTransition connections the handler has
isRunning: boolean, -- Whether a transition is running
isPaused: boolean, -- Whether the handler is paused
isDestroyed: boolean, -- Whether the handler was destroyed
startedAt: number?, -- When the most recent transition started
}| Field | Type | Description |
|---|---|---|
label | string | The label passed to track, or the rule name. |
rule | string | The name of the rule that created the handler. |
state | string | The active state. |
connections | number | How many onTransition connections the handler has. |
isRunning | boolean | Whether a transition is running. |
isPaused | boolean | Whether the handler is paused. |
isDestroyed | boolean | Whether the handler was destroyed. |
startedAt | number? | The os.clock() time at which the most recent transition started, or nil before the first one. |