43 lines
No EOL
2.4 KiB
HTML
43 lines
No EOL
2.4 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>max — Ludic</title>
|
||
<meta name="description" content="The larger 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">max</span></div>
|
||
<div class="item-head">
|
||
<span class="kind-badge kind-builtin">function</span>
|
||
<h1 id="top">max</h1>
|
||
</div>
|
||
<code class="sig">max(a, b) -> int</code>
|
||
<div class="desc"><p>Returns whichever of its two integer arguments is larger. Use it to enforce a lower bound (for example clamping a countdown so it never drops below zero with <code>max(remaining, 0)</code>), to track a running high score, or to pick the greater of two candidate values. For the smaller of two values use <code>min</code>, and to bound a value on both sides 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 HighScore {
|
||
var score: int = 0
|
||
var best_score: int = 0
|
||
|
||
handler EarnPoints phase Update {
|
||
score = score + 5
|
||
best_score = max(best_score, score)
|
||
if score >= 20 { quit() }
|
||
}
|
||
|
||
handler ReportBest phase Render {
|
||
Screen.clear(Color.MidnightBlue)
|
||
Screen.draw_number(x: 8, y: 8, value: best_score, color: Color.Gold, 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> |