Update query.md

This commit is contained in:
silly-spongus 2024-09-29 04:13:21 -03:00 committed by GitHub
parent b1810a25fe
commit 561a3a77de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,23 +2,21 @@
A World contains entities which have components. The World is queryable and can be used to get entities with a specific set of components. A World contains entities which have components. The World is queryable and can be used to get entities with a specific set of components.
To create a query, you must utilize [`world:query`](world). # Methods
## Methods ## drain
### drain
This method will impede it from being reset when the query is being iterated. This method will impede it from being reset when the query is being iterated.
```luau ```luau
function query:drain(): Query function query:drain(): Query
``` ```
### next ## next
Get the next result in the query. Drain must have been called beforehand or otherwise it will error. Get the next result in the query. Drain must have been called beforehand or otherwise it will error.
```luau ```luau
function query:next(): Query function query:next(): Query
``` ```
### with ## with
Adds components (IDs) to query with, but will not use their data. This is useful for Tags or generally just data you do not care for. Adds components (IDs) to query with, but will not use their data. This is useful for Tags or generally just data you do not care for.
```luau ```luau
@ -48,7 +46,7 @@ for (const [id, position] of world.query(Position).with(Velocity)) {
Put the IDs inside of `world:query()` instead if you need the data. Put the IDs inside of `world:query()` instead if you need the data.
::: :::
### without ## without
Removes entities with the provided components from the query. Removes entities with the provided components from the query.
```luau ```luau
@ -73,7 +71,7 @@ for (const [entity, position] of world.query(Position).without(Velocity)) {
``` ```
::: :::
### replace ## replace
This function takes a callback which is given the current queried data of each matching entity. The values returned by the callback will be set as the new data for each given ID on the entity. This function takes a callback which is given the current queried data of each matching entity. The values returned by the callback will be set as the new data for each given ID on the entity.
```luau ```luau
function query:replace( function query:replace(
@ -98,7 +96,7 @@ world
``` ```
::: :::
### archetypes ## archetypes
Returns the matching archetypes of the query. Returns the matching archetypes of the query.
```luau ```luau
function query.archetypes(): { Archetype } function query.archetypes(): { Archetype }