TypeScript guides
Engine basics tutorial
Define a Query
2 min
queries are the simplest concept to explain out of everything we have dealt with so far but we looked into them only briefly, so lets explore their technical properties anyway ir engine's definequery is a function that accepts an array https //developer mozilla org/en us/docs/web/javascript/reference/global objects/array of component types, and will return a javascript generator https //developer mozilla org/en us/docs/web/javascript/guide/iterators and generators#generator functions this generator can then be used in a for https //developer mozilla org/en us/docs/web/javascript/reference/statements/for loop to iterate over all entities that contain all components in the list that we provided (ie our array of components) the returned query can be named anything we want, as its name is only relevant for our project const helloquery = ecs definequery(\[hellocomponent]) for (const entity of helloquery()) { // do something for all entities that contain a hellocomponent }