ludic/annot-ondetach.html
2026-09-17 22:10:03 +00:00

48 lines
No EOL
2.7 KiB
HTML
Raw Permalink 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>@OnDetach — Ludic</title>
<meta name="description" content="Run a handler when a property is structurally detached from a live instance.">
<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">@OnDetach</span></div>
<div class="item-head">
<span class="kind-badge kind-annotation">annotation</span>
<h1 id="top">@OnDetach</h1>
</div>
<code class="sig">@OnDetach(Property) handler Name { … }</code>
<div class="desc"><p><code>@OnDetach(Property)</code> is the teardown counterpart to <code>@OnAttach</code>: it fires when the named property is structurally removed from a live instance with <code>detach P on e</code>. The hook runs <b>before</b> the property's presence flag clears, so its body can still read the outgoing field values one last time — useful for releasing whatever the property was tracking or logging its final state. It is distinct from <code>@OnDisable</code>, which pauses a property while keeping its data; detach actually destroys the property's presence on the instance. Add <code>@Public</code> to also emit a <code>prop_&lt;Property&gt;_detach</code> event.</p></div>
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program DetachHook {
property Tag { value: int = 0 }
property Shield { amount: int = 0 }
model Unit { Tag }
@OnDetach(Shield) handler DropShield { # fires as Shield is removed
print(Shield.amount + 20) # 25 — reads the outgoing amount
}
handler Seed phase Start {
spawn Unit { Tag { value: 1 } }
for (unit) in query [Unit] { attach Shield on self() { amount: 5 } }
}
handler RemoveShield phase Render {
for (shield) in query [Shield] {
detach Shield on self() # triggers @OnDetach
}
quit()
}
}</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>