State
new State()State - Key-value perception store with timestamps
Stores AI perception data written by Sensors and read by Intents. Each key tracks when it was last updated for staleness detection.
Usage
Example
// Sensor writes perception data
state.set('targetVisible', true);
state.set('targetPosition', { x: 10, y: 0, z: 5 });
// Intent reads perception data
const visible = state.get('targetVisible', false);
const pos = state.get('targetPosition');
// Check staleness
const age = state.getAge('targetVisible'); // seconds since update
Properties
Methods
set#
set(key : string, value : any) : StateSet a value in the state.
Parameters
keystringThe key to set.
valueanyThe value to store.
Returns
State — This instance for chaining.setMultiple#
setMultiple(entries : Object) : StateSet multiple values at once.
Parameters
entriesObjectObject with key-value pairs to set.
Returns
State — This instance for chaining.get#
get(key : string, defaultValue : any) : anyGet a value from the state.
Parameters
keystringThe key to get.
defaultValueoptionalanyValue to return if key doesn't exist.
Default is
Default is
null.Returns
any — The stored value or default.has#
has(key : string) : booleanCheck if a key exists in the state.
Parameters
keystringThe key to check.
Returns
boolean — True if the key exists.getAge#
getAge(key : string) : numberGet the age of a value in seconds.
Parameters
keystringThe key to check.
Returns
number — Seconds since last update, or Infinity if never set.delete#
delete(key : string) : booleanDelete a key from the state.
Parameters
keystringThe key to delete.
Returns
boolean — True if the key existed and was deleted.clear#
clear() : StateClear all state data.
Returns
State — This instance for chaining.update#
update(delta : number) : StateUpdate the internal time reference. Called each frame before sensors run.
Parameters
deltanumberTime delta in seconds.
Returns
State — This instance for chaining.keys#
keys() : Array<string>Get all keys in the state.
Returns
Array<string> — Array of all keys.