Skip to content
KCKingdoms Connected Scripting APIScripting guides and API
Runtime classClient APIGenerated

StateBag

Defined in: client/api.d.ts:5494

Arbitrary key/value state attached to one replicated entity, reached as entity.state. Keys set on the server replicate to every client that can currently see the entity.

get(key): any

Defined in: client/api.d.ts:5502

Reads one key from this entity’s state.

string

Key to read.

any

The stored value, or undefined when the key is not set.


has(key): boolean

Defined in: client/api.d.ts:5509

Checks whether this entity’s state holds a key.

string

Key to test.

boolean

True when the key is set.


keys(): string[]

Defined in: client/api.d.ts:5515

Lists the keys this entity’s state holds, sorted.

string[]

Every key currently set, in ascending order.


onChange(key, handler): Function

Defined in: client/api.d.ts:5529

Watches this entity’s state. The filter is applied before the handler runs, so a listener watching one key of one entity is not woken by unrelated changes. The subscription is dropped when the registering resource stops.

string | null

Only report this key, or null to report every key of this entity.

Function

Called as (key: string, value: any, previous: any) with the changed key, its new value and the value before it. value is undefined when the key was removed and previous is undefined when it held nothing.

Function

A zero-argument function that cancels this subscription.


toObject(): Record<string, any>

Defined in: client/api.d.ts:5521

Copies this entity’s whole state into a plain object.

Record<string, any>

Every key and value currently set. The copy does not track later changes.