42 lines
No EOL
2.8 KiB
HTML
42 lines
No EOL
2.8 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>@Queries — Ludic</title>
|
||
<meta name="description" content="Declare the properties a handler operates on, binding their fields by name in the body.">
|
||
<link rel="stylesheet" href="base.css">
|
||
<link rel="stylesheet" href="docs.css">
|
||
</head>
|
||
<body>
|
||
<header class="nav"><div class="wrap nav-in"><a class="brand" href="index.html"><span class="logo">L</span> Ludic</a><button class="nav-toggle" aria-label="Toggle menu" aria-expanded="false">☰</button><nav class="nav-links"><a href="index.html">Home</a><a href="api.html">API Reference</a><a class="nav-cta" href="https://git.workshopsoft.io/workshopsoft/ludic">Source ↗</a></nav></div></header>
|
||
<main class="wrap item">
|
||
<div class="crumbs"><a href="api.html">API Reference</a> <span>›</span> <a href="api.html#annotations">Annotations</a> <span>›</span> <span class="here">@Queries</span></div>
|
||
<div class="item-head">
|
||
<span class="kind-badge kind-annotation">annotation</span>
|
||
<h1 id="top">@Queries</h1>
|
||
</div>
|
||
<code class="sig">@Queries(these: [Position, Velocity])</code>
|
||
<div class="desc"><p><code>@Queries</code> lets a handler declare the properties it operates on up front, and the compiler wraps the whole body in a query loop over the matching model instances. The body then runs once per match with each listed property bound by name — you write <code>Position.column</code> directly instead of opening a <code>for (…) in query […]</code> yourself — and <code>self()</code> gives the current instance. It takes the same shape as a manual query: <code>these: [ … ]</code> lists the required properties (each may carry a filter like <code>Health{current <= 0}</code>), and an optional <code>on: Model</code> restricts the match to instances of one model. Reach for it when a handler's entire job is "for every matching instance, do this"; drop to an explicit <code>query</code> when you need finer control inside the loop.</p></div>
|
||
|
||
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program AdvanceMovement {
|
||
property Position { column: int = 0, row: int = 0 }
|
||
property Velocity { delta_x: int = 0, delta_y: int = 0 }
|
||
model Player { Position, Velocity }
|
||
|
||
@Queries(these: [Position, Velocity], on: Player) # body runs once per matching Player
|
||
handler AdvancePositions phase FixedUpdate {
|
||
Position.column = Position.column + Velocity.delta_x
|
||
Position.row = Position.row + Velocity.delta_y
|
||
}
|
||
|
||
handler SpawnPlayer phase Start {
|
||
spawn Player { Position { column: 0, row: 0 }, Velocity { delta_x: 1, delta_y: 0 } }
|
||
}
|
||
}</pre></div>
|
||
|
||
<a class="back" href="api.html">← All symbols</a>
|
||
</main>
|
||
<script src="ludic-highlight.js"></script>
|
||
<script>Ludic.highlightAll(); Ludic.installCards(); Ludic.flashTarget();</script>
|
||
</body></html> |