Skip to content

Query

Type

Query matches entities that have every given component and Pair. World.Query returns one typed by the components it reads (Query1 through Query8), and Query has the members they all share. #query is the number of matched entities, and for e, a, b in query do visits each one with the values of its queried components. query:Optional(component) adds a component that a matched entity may lack; it reads as nil there.

Column

Field
Column: QueryColumnFn

Column returns the Column of a queried component or Pair.

Entities

Method
Entities() -> Column<Entity>

Entities returns the Column of matched entities.

With

Method
With(...(ComponentHandle | PairHandle | FlagHandle)) -> Query

With adds a required component or Pair and returns the query (up to 8 terms total).

Example

-- Server script in a part.
self:Add(Component.Timer)

local timed = World.Query(Component.Position):With(Component.Timer)
print(#timed) -- prints 1

Without

Method
Without(...(ComponentHandle | PairHandle | FlagHandle)) -> Query

Without excludes entities that have a component or Pair and returns the query.

Example

-- Server script in a part.
local nonClimbable = World.Query(Component.Position):Without(Component.Climbable)
print(#nonClimbable >= 1) -- prints true

IncludeInactive

Method
IncludeInactive() -> Query

IncludeInactive returns a query that also matches inactive entities.

System

Method
System(name: string, fn: (q: Query, dt: number) -> (), phase: SystemPhase?, after: string?) -> ()

System registers fn under name and runs it on every tick with the query and the frame time in seconds. Pass a phase to pick when it runs and after to order it after the system with that name.