API Reference › Query › Query.first
method

Query.first

Query.first(prop) -> int

Returns the first (lowest entity id) live entity that carries prop, or -1 if none do. Handy for a singleton-ish lookup — the player, the current boss, the one active portal — and to test existence (Query.first(prop) >= 0). Read its fields with World.get.

Parameters

propa property id (from World.prop_id("Name"))

Example

program Demo {
  property Player { hp: int = 0 }
  model Hero { Player }
  entry {
    spawn Hero { Player { hp: 100 } }
    let P  = World.prop_id("Player")
    let hp = World.field_id(P, "hp")
    let e  = Query.first(P)
    if e >= 0 { print(World.get(e, P, hp)) }   # 100
  }
}
← All symbols