--- id: query-within name: Query.within category: query kind: namespace-method tokens: Query.within sig: Query.within(prop, pos, x, y, radius, x_field, y_field) -> []int tip: Every bearer of prop inside a radius of a point. order: 4 ns: Query member: within --- Returns the live entities carrying prop whose position is within radius of (x, y), as a []int of entity ids in ascending id order — index it with len / [i]. Position is read from property pos at x_field/y_field, exactly as in Query.nearest. The boundary is inclusive (distance <= radius), measured by exact integer distance. Use it for area-of-effect damage, proximity triggers, flocking neighbours, or "what's near the cursor". Parameters: - `prop` — the property that filters which entities are considered - `pos` — the property holding the coordinates - `x`, `y` — the centre of the query - `radius` — the inclusive radius - `x_field`, `y_field` — field ids of the x / y coordinate within `pos` ```ludic program Demo { property Position { col: int = 0, row: int = 0 } property Unit { hp: int = 0 } model Soldier { Position, Unit } entry { spawn Soldier { Position { col: 1, row: 1 }, Unit { hp: 5 } } spawn Soldier { Position { col: 8, row: 8 }, Unit { hp: 5 } } let U = World.prop_id("Unit") let P = World.prop_id("Position") let cx = World.field_id(P, "col") let cy = World.field_id(P, "row") let hit = Query.within(U, P, 0, 0, 3, cx, cy) # just the (1,1) soldier print(len(hit)) # 1 } } ```