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.
Type Parameters
Section titled “Type Parameters”Value extends object
Parameters
Section titled “Parameters”Value
label?
Section titled “label?”string
Returns
Section titled “Returns”ResourceHandle<Value>
Example
Section titled “Example”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')}