Skip to main content

Entities

BeforeDespawn

await this.BeforeDespawn

Waits until just before the entity is despawned.

Despawn

this.Despawn -> boolean

Immediately despawns the entity, removing it from the world. Returns true if this still exists and was just despawned. Returns false if this does not exist or is nullish.

DespawnBefore

this.DespawnBefore(parent)

Causes this to be despawned just before parent is despawned, whenever that occurs.

Exists

Exists(this) -> boolean

Returns true if the entity still exists, false if it has been despawned or is not an entity.

Expire

this.Expire

Registers to despawn this entity in the next reap phase, which is normally later in the tick. Sometimes despawning an entity in the middle of processing can cause problems, as there may be currently-executing code that is still using the entity. This is sometimes a safer than calling Despawn directly.

Query

Query(filter?, against?=, [owner?]) -> array

Returns an array of all entities that match the given criteria.

  • filter (Categories): Each entity's Category must overlap at least one of these categories. Defaults to Category:All.
  • against (Flags) and owner (Entity): The alliance status between each entity and owner must overlap at least one of these alliance flags. Defaults to Alliance:All.

Only entities with their Category property assigned will be considered by this function, even if filter is Category:All. If no entities match, returns an empty array.

QueryAny

QueryAny(filter?, against?=, [owner?]) -> entity

Finds the first entity that matches the given criteria.

  • filter (Categories): The entity's Category must overlap at least one of these categories. Defaults to Category:All.
  • against (Flags) and owner (Entity): The alliance status between the entity and owner must overlap at least one of these alliance flags. Defaults to Alliance:All.

Only entities with their Category property assigned will be considered by this function, even if filter is Category:All. If no entity matches, returns undefined.

QueryCount

QueryCount(filter?, against?=, [owner?]) -> number

Returns the Number of entities that match the given criteria.

  • filter (Categories): Each entity's Category must overlap at least one of these categories. Defaults to Category:All.
  • against (Flags) and owner (Entity): The alliance status between each entity and owner must overlap at least one of these alliance flags. Defaults to Alliance:All.

Only entities with their Category property assigned will be considered by this function, even if filter is Category:All.

Spawn

Spawn |use this = entity| { } -> entity

Spawns a new entity.

The subblock defines the main behavior for the entity. The main behavior block will execute concurrently with the rest of the game. When the entity despawns, its main behavior will be terminated (along with all other behaviors attached to the entity).

This function will return as soon as the subblock reaches an await and goes to sleep.

await Spawn |use this = entity| { }

Spawns a new entity, then waits for it to despawn before continuing.

The subblock defines the main behavior for the entity. The main behavior block will execute concurrently with the rest of the game. When the entity despawns, its main behavior will be terminated (along with all other behaviors attached to the entity).

Subspawn

this.Subspawn |use this = entity| { } -> entity

Spawns a new subentity with this as its parent. When the parent despawns, the subentity will be despawned first.

The subblock defines the main behavior for the new entity, and will execute concurrently with the rest of the game. When the subentity despawns, all of its behaviors will be terminated.

This function returns as soon as its delve block reaches an await and goes to sleep.

await this.Subspawn |use this = entity| { }

Spawns a new subentity with this as its parent, then waits for it to despawn before continuing. When the parent despawns, the subentity will be despawned first.

The subblock defines the main behavior for the new entity, and will execute concurrently with the rest of the game. When the subentity despawns, all of its behaviors will be terminated.

World

World -> entity

Returns the global entity World. This entity exists before the game starts and will exist until the game ends. It can never be despawned. World can be used to create global properties, behaviors, signals, etc.