1.2 KiB
1.2 KiB
| id | name | category | kind | tokens | sig | tip | order |
|---|---|---|---|---|---|---|---|
| fn-max | max | builtins | builtin | max | max(a, b) -> int | The larger of two integers. | 50 |
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 max(remaining, 0)), to track a running high score, or to pick the greater of two candidate values. For the smaller of two values use min, and to bound a value on both sides at once use clamp.
Parameters:
a— the first valueb— the second value
program HighScore {
state HighScoreState {
score: int = 0
best_score: int = 0
}
handler EarnPoints(high_score_st: mut HighScoreState) phase Update {
high_score_st.score = high_score_st.score + 5
high_score_st.best_score = max(high_score_st.best_score, high_score_st.score)
if high_score_st.score >= 20 { quit() }
}
handler ReportBest(high_score_st: HighScoreState) phase Render {
Screen.clear(Color.MidnightBlue)
Screen.draw_number(x: 8, y: 8, value: high_score_st.best_score, color: Color.Gold, scale: 1)
Screen.show()
}
}