49 lines
No EOL
2.6 KiB
HTML
49 lines
No EOL
2.6 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>min — Ludic</title>
|
||
<meta name="description" content="The smaller of two integers.">
|
||
<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#builtins">Builtin functions</a> <span>›</span> <span class="here">min</span></div>
|
||
<div class="item-head">
|
||
<span class="kind-badge kind-builtin">function</span>
|
||
<h1 id="top">min</h1>
|
||
</div>
|
||
<code class="sig">min(a, b) -> int</code>
|
||
<div class="desc"><p>Returns whichever of its two integer arguments is smaller. Use it to enforce an upper bound — for instance capping healing so it never exceeds a maximum with <code>min(current + heal, maximum)</code> — or to pick the lesser of two candidate values. For the larger of two values use <code>max</code>, and to bound a value between a low and a high at once use <code>clamp</code>.</p></div>
|
||
<div class="params"><h2>Parameters</h2><div class="param" id="param-a"><code class="pname">a</code><span class="pdesc">the first value</span></div><div class="param" id="param-b"><code class="pname">b</code><span class="pdesc">the second value</span></div></div>
|
||
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program CappedHealing {
|
||
property Health { current: int = 100, maximum: int = 100 }
|
||
model Player { Health }
|
||
|
||
handler SpawnPlayer phase Start {
|
||
spawn Player { Health { current: 90, maximum: 100 } }
|
||
}
|
||
|
||
handler ApplyHeal phase Update {
|
||
for (Health) in query [Health, {Player}] {
|
||
Health.current = min(Health.current + 25, Health.maximum)
|
||
}
|
||
}
|
||
|
||
handler ReportHealth phase Render {
|
||
Screen.clear(Color.MidnightBlue)
|
||
for (Health) in query [Health, {Player}] {
|
||
Screen.draw_number(x: 8, y: 8, value: Health.current, color: Color.LimeGreen, scale: 1)
|
||
}
|
||
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> |