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

45 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>@OnDisable — Ludic</title>
<meta name="description" content="Run a handler when a property is paused (disabled) on an 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">@OnDisable</span></div>
<div class="item-head">
<span class="kind-badge kind-annotation">annotation</span>
<h1 id="top">@OnDisable</h1>
</div>
<code class="sig">@OnDisable(Property) handler Name { … }</code>
<div class="desc"><p><code>@OnDisable(Property)</code> fires when a present property is paused with <code>disable P on e</code>. Disabling keeps the property's data intact and simply stops it from participating — the logical "off" switch — so this hook is the moment a capability goes dormant, not the moment it is destroyed (that is <code>@OnDetach</code>). The body runs in the instance's context and can read the fields before they go quiet, which is handy for cleaning up an effect the property was driving. It pairs with <code>@OnEnable</code> for capabilities that toggle on and off repeatedly. Add <code>@Public</code> to also emit a <code>prop_&lt;Property&gt;_disable</code> event.</p></div>
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program DisableHook {
property Tag { value: int = 0 }
property Shield { amount: int = 0 }
model Unit { Tag, Shield }
@OnDisable(Shield) handler ShieldDown { # fires when Shield is disabled
print(Shield.amount) # 5 — data is retained, just paused
}
handler Seed phase Start { spawn Unit { Tag { value: 1 }, Shield { amount: 5 } } }
handler Deactivate phase Render {
for (unit) in query [Unit] {
disable Shield on self() # triggers @OnDisable
}
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>