API Reference › Control flow › where
keyword

where

for (Binds) in query [Comps] where cond { … }

where attaches a boolean condition to a query loop, so the body runs only for entities whose components satisfy it — the rows that fail the test are skipped entirely. The condition is an ordinary expression over the bound components, such as where Battle.hp <= 0 and Battle.side == 1. It is the imperative twin of a component filter written inside a @Queries annotation, and keeps the guard next to the loop instead of repeating an if at the top of the body.

Example

program Cleanup {
  property Health { hp: int = 0 }
  model Foe { Health }

  handler ReapDead phase LateUpdate {
    for (Health) in query [Health, {Foe}] where Health.hp <= 0 {
      # only dead foes reach here
    }
  }
}
← All symbols