Zum Hauptinhalt springen

ecs

Properties​

Types​

info

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.

TypeDescription
ecs.eidEntity Reference
ecs.f3232-bit floating-point number
ecs.f6464-bit floating-point number
ecs.i3232-bit integer
ecs.ui88-bit unsigned integer
ecs.ui3232-bit unsigned integer
ecs.stringString
ecs.booleanBoolean

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​

ParameterTypeDescription
triggers (Required)Record<String, Trigger[]>Name of the next states that this state and transition to and the triggers to do so.
onEnterfunctionFunction called before the state is entered.
onExitfunctionFunction called before the state is entered.

Trigger​

EventTrigger​
ParameterTypeDescription
type (Required)constant: 'event'A constant to indicate the type of the trigger
event (Required)stringThe event type that triggers this
targeteidThe entity you want this trigger to change state for
beforeTransition(event) => booleanA function that run before the transition, if the result is truthy then the transition will terminate and the state will not change
TimeoutTrigger​
ParameterTypeDescription
type (Required)constant: 'timeout'A constant to indicate the type of the trigger
timeout (Required)numberThe 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​
ParameterTypeDescription
targeteidthe entity you want this trigger to change state for
beforeTransition(event) => booleanFunction 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