math.clamp

Clamps a number between a minimum and maximum value. This function will error if min > max.

Usage

math.clamp(value, min, max)

Arguments

Name Type Description
value number Number to clamp.
min number Clamping lower bound.
max number Clamping upper bound.

Returns

Name Type Description
clamped number Clamped value.

Examples

local clamped = math.clamp(896, 100, 200);
print(clamped); -- Prints "200"
local clamped = math.clamp(-50, 100, 200);
print(clamped); -- Prints "100"
local clamped = math.clamp(125, 100, 200);
print(clamped); -- Prints "125"

This site uses Just the Docs, a documentation theme for Jekyll.