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

56 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>exit — Ludic</title>
<meta name="description" content="The scene-exit hook — runs once as a scene is left.">
<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#scenes">Scenes &amp; layers</a> <span>›</span> <span class="here">exit</span></div>
<div class="item-head">
<span class="kind-badge kind-keyword">keyword</span>
<h1 id="top">exit</h1>
</div>
<code class="sig">on exit { … }</code>
<div class="desc"><p><code>exit</code> names the body of a scene's exit hook, written <code>on exit { … }</code>. It runs <b>once</b> when the scene is left — on a <code>become Other</code>, the leaving scene's <code>on exit</code> runs first, then the active scene switches and the new scene's <code>on enter</code> runs. Use it to tear down what the scene created so it does not leak into the next state: despawn the scene's models, hide a menu, save progress. Like <code>on enter</code>, it is a lifecycle hook rather than a phase and holds plain statements, not <code>phase</code> handlers.</p></div>
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program ExitHookExample {
property Position { column: int = 0, row: int = 0 }
model Enemy { Position }
scene Battle start {
on enter { spawn Enemy { Position { column: 8, row: 4 } } }
on exit {
for (any_position) in query [Position, {Enemy}] { despawn self() }
}
layer Fight {
handler LeaveBattle phase Update {
if Input.key() == 'q' { become Overworld }
}
handler DrawBattle phase Render {
Screen.clear(Color.Crimson)
Screen.show()
}
}
}
scene Overworld {
layer World {
handler DrawWorld phase Render {
Screen.clear(Color.MidnightBlue)
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>