SharedState

Values attached to a player, horse or NPC, through entity.state. Values can be booleans, numbers, strings or anything else JSON holds. Keys can have up to 64 bytes and values up to 4096 bytes, with up to 128 keys per entity. The server writes, and clients read what is sent to them.

sharedState.set()

set(key, value, options = {})

Sets a key and returns true if something changed. `scope` decides who receives it: 'broadcast', all players, the default; 'owner', only the player the entity belongs to; or 'server', nobody.

sharedState.remove()

remove(key)

Removes a key and returns true if it existed.

sharedState.get()

get(key)

A key's value, or undefined.

sharedState.has()

has(key)

Whether a key is set.

sharedState.keys()

keys()

All keys, sorted.

sharedState.toObject()

toObject()

All keys and values as a plain object.

sharedState.onChange()

onChange(key, handler)

Calls a handler when a key changes, or any key if you pass null. Returns a function that removes the handler.