clamp
NOTE: The GameMaker function of the same name produces the same results and obsoletes this script.
This function clamps an input two an upper or lower bound, or min/max values. It returns the value a when t is less than a, the value t when t is between a and b, and the value b when t is greater than b.
- clamp(x,a,b)
- Returns a when (x < a), b when (x > b), x otherwise.
COPY/// clamp(x,a,b)
//
// Returns a when (x < a), b when (x > b), x otherwise.
//
// x value, real
// a lower bound, real
// b upper bound, real
//
/// GMLscripts.com/license
{
if (argument0 < argument1) return argument1;
if (argument0 > argument2) return argument2;
return argument0;
}
Contributors: xot
GitHub: View · Commits · Blame · Raw