ludic/docs/language/math/math-max.md

877 B

id name category kind tokens sig tip order ns member
math-max Math.max math namespace-method Math.max Math.max(a, b) -> int The larger of two values. 1 Math max

Returns whichever of a and b is larger. Like Math.min, it works for both int and fixed operands. Use it to hold a value at a floor — for example keeping a countdown at zero instead of going negative, or a health bar from dropping below the minimum. The bare form max(a, b) is kept as a convenience alias.

Parameters:

  • a — the first value
  • b — the second value
program Countdown {
  state CountdownState {
    timer: int = 60
  }

  handler Tick(countdown_st: mut CountdownState) phase Update {
    countdown_st.timer = Math.max(countdown_st.timer - 1, 0)   # stops at 0, never negative
  }
}