ecs
Propertiesβ
Typesβ
Currently, storing dynamically sized objects or lists isnβt supported. Weβre actively exploring this feature and would love to hear about your specific use cases.
The following data types are useful for creating Schema properties on a Custom Component or references to a specific type.
Type | Description |
---|---|
ecs.eid | Entity Reference |
ecs.f32 | 32-bit floating-point number |
ecs.f64 | 64-bit floating-point number |
ecs.i32 | 32-bit integer |
ecs.ui8 | 8-bit unsigned integer |
ecs.ui32 | 32-bit unsigned integer |
ecs.string | String |
ecs.boolean | Boolean |
Functionsβ
registerComponentβ
Registers a component with the ECS.
ecs.registerComponent({
name: string,
schema: Schema,
data: Schema,
schemaDefaults: Object,
add: function
remove: function,
tick: function
}) // -> Component Handle
Stateβ
Parameter | Type | Description |
---|---|---|
triggers (Required) | Record<String, Trigger[]> | Name of the next states that this state and transition to and the triggers to do so. |
onEnter | function | Function called before the state is entered. |
onExit | function | Function called before the state is entered. |
Triggerβ
EventTriggerβ
Parameter | Type | Description |
---|---|---|
type (Required) | constant: 'event' | A constant to indicate the type of the trigger |
event (Required) | string | The event type that triggers this |
target | eid | The entity you want this trigger to change state for |
beforeTransition | (event) => boolean | A function that run before the transition, if the result is truthy then the transition will terminate and the state will not change |
TimeoutTriggerβ
Parameter | Type | Description |
---|---|---|
type (Required) | constant: 'timeout' | A constant to indicate the type of the trigger |
timeout (Required) | number | The number of milliseconds before the transition |
createStateMachineβ
Create a state machine.
ecs.createStateMachine(world, owner, {initialState: string, states: Record<string, State>}) // -> State Machine ID
deleteStateMachineβ
Delete a state machine.
ecs.deleteStateMachine(world, machineId) // -> void
defineStateβ
Define a state.
ecs.defineState(name: string) // -> State
initialβ
Mark this state as the initial state of the state machine
ecs.defineState(name).initial() // -> void
onEnterβ
Set a callback to run when entering this state.
ecs.defineState(name).onEnter(callback) // -> void
onEventβ
Eventβ
Parameter | Type | Description |
---|---|---|
target | eid | the entity you want this trigger to change state for |
beforeTransition | (event) => boolean | Function that run before the transition, if the result is truthy then the transition will terminate and the state will not change |
Trigger a transition to the next state when an event is received.
ecs.defineState(name).onEvent(event: string, nextState: string | State, args: EventObject) // -> void
onExitβ
Set a callback to run when exiting this state.
ecs.defineState(name).onExit(callback) // -> void
waitβ
Wait before transitioning state.
ecs.defineState(name).wait(waitTime: number, nextState: string | State) // -> void
defineSystemβ
Define a system.
ecs.defineSystem([terms]: string[], behavior: function) // -> System
defineQueryβ
Define a query.
ecs.defineQuery([terms: string]) // -> callback
getAttributeβ
Built-in components are also exposed as a property of ecs.
ecs.getAttribute(attributeName: string) // -> the attribute that has been registered with that name.
listAttributesβ
Returns a list of attributes.
ecs.listAttributes() // -> string[]
getBehaviorsβ
Returns a list of registered behaviors.
ecs.getBehaviors() // -> function[]
registerBehaviorβ
Register a function that runs on the world every tick.
ecs.registerBehavior(behavior: function) // -> void
unregisterBehaviorβ
Deactivate a behavior.
ecs.unregisterBehavior(behavior: function) // -> void