StreamWizard.state stores a JSON blob per placed widget, so death counters
and sub goals survive OBS restarts and stream ends.
The API
get() returns your saved object, or {} if nothing was saved yet;
set() replaces it.
Spread the old state if you’re only changing one key.
A complete counter
Good to know
- Per placement: two copies of the same widget on different overlays have separate state.
- The editor never changes your real state: see testing in the editor below.
- Up to 16KB:
set()takes a plain object of JSON values, at most 16KB saved, with keys up to 64 characters. A bigger save is rejected and your old state stays. - Don’t save on every frame: batch it. Save after a change settles, not
inside an animation loop. Each widget API call counts toward a limit of 60
a minute per overlay, shared with
userStateand Twitch lookups. - Older widgets using
window.StreamWizard.stateUrlwith manualfetchstill work on an overlay;state.get/setis the same API with the plumbing done. In the editorstateUrlisnull, so switch tostate.get/setto test them there.
Channel state: StreamWizard.userState
StreamWizard.state is private to one placed widget. StreamWizard.userState
is shared across the whole channel, stored key by key, and written by
StreamWizard’s servers too — which is the part that matters. A widget only
receives events while it is open, so anything you derive from an event is wrong
the moment the overlay was closed when it fired. Channel state is still there
when the widget comes back.
a-z, 0-9 or _. Values are any JSON up to 8KB,
and a channel can hold 200 keys.
Counters: use increment
Never build a counter with get then set — two writers racing (a mod
command and a widget, or two open overlays) lose updates. increment adds on
the server atomically and resolves to the new value:
delete(key)
removes a key entirely.
Live updates: subscribe
Every channel-state change — from this widget, another widget, StreamWizard’s
servers, or (soon) chat commands — is pushed to open overlays the moment it
lands. No polling:
subscribe(key, cb) and onChange(cb) (all keys, sys. included) both
return an unsubscribe function. Registering is safe anywhere. The raw frame
also arrives as an onEventReceived with listener streamwizard.user_state
and event { key, value, updatedAt }, if you prefer one event handler.
Server-written keys
Keys beginningsys. are written by StreamWizard and are read-only — a widget
that could write them could lie about what the channel is doing.
This is how to react to something that happened while you were closed. Rather
than resetting a total on
stream.online — which does nothing if the overlay
opens later — record which stream the total belongs to and compare on load:
Testing in the editor
Testing a counter shouldn’t change the one on stream. In the overlay editor and the widget code editor, both APIs work, with one rule: reads are real, writes stay in the editor.state.get(),userState.get()andgetAll()read your real saved values on the overlay editor canvas. The widget code editor has no overlay to read from, so there they start empty.set,incrementanddeletechange an editor-only copy. Nothing is sent to the real store, so your overlay in OBS never sees them.onChangeandsubscribefire for those editor writes, just like they would live.
userState, and the box under each widget is its own state. Typed values win
over the real ones, and a widget whose state you edit reloads to pick it up.
Use real values again throws the editor copy away.
The tab shows up when a widget on the canvas uses StreamWizard.state or
StreamWizard.userState. The values are kept per overlay in your browser and
never leave it.
