docs: regenerate site from f094acfdb5
This commit is contained in:
commit
63c5ed9baf
975 changed files with 55427 additions and 0 deletions
51
kw-machine.html
Normal file
51
kw-machine.html
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>machine — Ludic</title>
|
||||
<meta name="description" content="An explicit state machine over an int var — dispatches on the store's value.">
|
||||
<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#control">Control flow</a> <span>›</span> <span class="here">machine</span></div>
|
||||
<div class="item-head">
|
||||
<span class="kind-badge kind-keyword">keyword</span>
|
||||
<h1 id="top">machine</h1>
|
||||
</div>
|
||||
<code class="sig">machine store { state Name { … } }</code>
|
||||
<div class="desc"><p>A <code>machine</code> turns an integer store into an explicit state machine, replacing brittle <code>if phase == N</code> chains. It reads the store — a named program-scope <code>var</code> is the modern choice — and dispatches to the matching <code>state</code> block; inside a state, <code>become Name</code> transitions to another state of the same machine. States number themselves by declaration order (the first is <code>0</code>, the next <code>1</code>, and so on), so you never write magic constants, though <code>state Name = expr</code> is accepted when a state needs a specific value. Because <code>become</code> compiles to a single store back into the <code>var</code>, the whole machine lowers to plain branches with no dispatch table. Place a <code>machine</code> inside a handler so it runs each frame.</p></div>
|
||||
|
||||
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program TurnOrder {
|
||||
enum Phase { KnightMenu, KnightResolve, EnemyTurn }
|
||||
var battle_phase: int = Phase.KnightMenu
|
||||
|
||||
handler RunTurn phase Update {
|
||||
machine battle_phase {
|
||||
state KnightMenu {
|
||||
if Input.key() == ' ' { become KnightResolve }
|
||||
}
|
||||
state KnightResolve {
|
||||
become EnemyTurn
|
||||
}
|
||||
state EnemyTurn {
|
||||
become KnightMenu
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handler DrawWorld phase Render {
|
||||
Screen.clear(Color.MidnightBlue)
|
||||
Screen.draw_number(x: 8, y: 8, value: battle_phase, color: Color.Gold, scale: 2)
|
||||
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>
|
||||
Loading…
Add table
Add a link
Reference in a new issue