Clamp

Constrains a value to a [min, max] range. Returns min if the input is below, max if above, the input otherwise.

Category: Math Returns: matches the input type; see overloads.

Signature

Clamp(value, min, max)

The runtime picks the overload that matches the argument types. Mixing types (e.g. clamping an int with decimal bounds) routes through the number overload.

Overloads

ArgsReturnsNotes
(int, int, int)intAll-integer; result is integer.
(decimal, decimal, decimal)decimalAll-decimal; result is decimal.
(number, number, number)numberFallback when types can’t be statically resolved (e.g. variable inputs).

Examples

Clamp(hp, 0, maxHp)             // pin hp to a valid range
Clamp(score + bonus, 0, 100)    // ceiling at 100 after addition
Clamp(temperature, -40, 50)     // bounded weather variable
Docs last synced: 2026-07-08
Screenshot viewer