Skip to content
Untitled Sandbox - Developer Documentation
docs/types/State

State<T>

A single value shared across your scripts that tells you when it changes, which you create with state.create.

Events

changedEvent<(T, T)>

You listen to these with :connect, which the Event page covers.

State:get

method

Gives a copy of the current value, so changing that copy does nothing until you set it.

State:get() -> T
example
print(score:get())

Use it forreading the current round number or game phase from any of your scripts.

State:set

method

Changes the value, and fires changed when the new value is different.

State:set(value: T) -> ()
example
score:set(10)

Use it forswitching the game phase from lobby to playing, which every listening script can react to.

valueThe new value.

State:update

method

Hands your function the current value, and saves whatever it gives back.

State:update(update: (T) -> T) -> ()
example
score:update(function(value) return value + 1 end)

Use it foradding a new name to the list of round winners without losing the names already there.

updateGets the value and returns the new one.

State:increment

method

Adds to a number value, or takes away, and gives back the new value.

State:increment(amount: number?) -> number
example
score:increment(5)

Use it forcounting how many rounds have been played so far.

amountoptionalHow much to add, 1 by default. A negative amount takes away.
↑ ↓ moveEnter openEsc close