ludic/kw-model.html
2026-09-17 22:10:03 +00:00

46 lines
No EOL
2.6 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>model — Ludic</title>
<meta name="description" content="A named kind of thing — a fixed bundle of properties you spawn by one name.">
<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#structure">Program structure</a> <span>›</span> <span class="here">model</span></div>
<div class="item-head">
<span class="kind-badge kind-keyword">keyword</span>
<h1 id="top">model</h1>
</div>
<code class="sig">model Name { PropA, PropB, … }</code>
<div class="desc"><p>A <code>model</code> names a <b>kind</b> of thing in your game and the fixed set of properties every instance of it carries. Instead of attaching properties one by one, you <code>spawn</code> the model by name and every listed property comes with it, seeded from its defaults. A model's name doubles as a query tag: write <code>{Player}</code> inside a <code>query [...]</code> to match only instances of that model. The model itself has no fields of its own, so you never bind it to a variable — you bind its properties and filter by its tag.</p></div>
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program Arena {
property Position { column: int = 0, row: int = 0 }
property Velocity { delta_x: int = 0, delta_y: int = 0 }
property Health { current: int = 100, maximum: int = 100 }
model Player { Position, Health }
model Enemy { Position, Velocity, Health }
handler Spawn phase Start {
spawn Hero { Position { column: 2, row: 8 } }
spawn Grunt { Position { column: 18, row: 8 }; Velocity { delta_x: -1 } }
}
handler AdvanceEnemies phase Update {
for (position, velocity) in query [Position, Velocity, {Enemy}] {
position.column = position.column + velocity.delta_x
}
}
}</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>