Skip to content
Work in progress. These docs describe Spawnite at launch, and some parts are still being built.

updateEach

updateEach<T>(writer, query, callback): void

Walks each entity query matches, hands its traits’ fields to callback, and writes back what the callback changed. For example, updateEach(step, lamps, ([lamp]) => { if (!lamp.isLit) lamp.isLit = true; }) lights every lamp, with lamps made once as createQuery(LampTrait). Its first argument is what may write each record it hands, and it visits the entities that writer may write, as PassWriter says. On a page, a query that hands a trait the room streams visits the page’s own entities alone, and one that hands a predicted trait what the player’s page predicts. On the room and in a game played alone, every entity. Unlike Netcode for Entities, whose query opts into its Simulate filter, the writer’s reach decides, so a system that runs on both ends writes the room’s entities on the room and the page’s on the page. It reads as readEach does, then writes each trait back as koota’s updateEach does: a trait something watches is compared and, where it changed, its watchers are told once the pass ends; every other is written back unread. On a query of traits and Not alone, a Changed query is not told, so it holds the same entities whether a view watches or not: use setTrait for a write a Changed query must see. A query with Or, a tracking modifier or a relation runs koota’s own updateEach, which tells both while something watches. It walks the entities as they stood when it began, as readEach does, and skips one destroyed during it, so a callback may destroy any entity of the walk.

Type Parameter
T extends QueryParameter[]
Parameter Type
writer PassWriter<T>
query Query<T>
callback EachCallback<T>

void