Skip to content

resource

resource<Value>(value, label?): ResourceHandle<Value>

Defined in: src/handle.ts:601

Creates a new resource with the given initial value.

Resources exist independently of entities (and cannot be attached to them). They are useful to represent global state, such as game state, settings and so on.

Additionally, a label can be provided for easier identification during debugging.

Value extends object

Value

string

ResourceHandle<Value>

const GameState = resource('lobby')
function startGame() {
// `read` and `write` are used instead of `get` and `set` when it comes to
// interacting with the value of a resource.
print(`Game state transitioning from ${GameState.read()} to in-game.`)
GameState.write('in-game')
}