45 lines
No EOL
2.8 KiB
HTML
45 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>property — Ludic</title>
|
||
<meta name="description" content="A named record of typed fields — a per-model component, or a plain heap record.">
|
||
<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">property</span></div>
|
||
<div class="item-head">
|
||
<span class="kind-badge kind-keyword">keyword</span>
|
||
<h1 id="top">property</h1>
|
||
</div>
|
||
<code class="sig">property Name { field: T = default, … }</code>
|
||
<div class="desc"><p>A <code>property</code> declares a named record of typed fields, each with a default value. It is the one record keyword in Ludic, and how you <b>use</b> it decides how it is stored: list it in a <code>model</code> (or <code>attach</code> it with <code>spawn</code>) and it becomes a per-instance component held in the engine's storage and bound in queries; construct it with <code>new</code> and it becomes a plain heap record addressed by a pointer. Fields carry a type and a default, so a freshly spawned or <code>new</code>-ed property starts fully seeded. Give fields descriptive names — <code>column</code>/<code>row</code>, not <code>x</code>/<code>y</code> — because those names are what handlers read and write.</p></div>
|
||
|
||
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program Descent {
|
||
property Position { column: int = 0, row: int = 0 }
|
||
property Health { current: int = 100, maximum: int = 100 }
|
||
model Player { Position, Health }
|
||
|
||
handler Spawn phase Start {
|
||
spawn Hero { Position { column: 4, row: 4 }; Health { current: 80 } }
|
||
}
|
||
|
||
handler DrawWorld phase Render {
|
||
Screen.clear(Color.MidnightBlue)
|
||
for (position, health) in query [Position, Health, {Player}] {
|
||
let bar_width = health.current / 4
|
||
Screen.fill_rectangle(x: position.column, y: position.row, width: bar_width, height: 4, color: Color.Crimson)
|
||
}
|
||
Screen.show()
|
||
}
|
||
}</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> |