Real-valued functions

Game Maker 8

Real-valued functions

The following functions exist that deal with real numbers.

random(x) Returns a random real number between 0 and x. The number is always smaller than x.
random_range(x1,x2) Returns a random real number between x1 (inclusive) and x2 (exclusive).
irandom(x) Returns a random integer number between 0 and x (inclusive when x is an integer).
irandom_range(x1,x2) Returns a random real number between x1 (inclusive) and x2 (inclusive). Both x1 and x2 must be integer values (otherwise they are rounded down).
random_set_seed(seed) Sets the seed (an integer) that is used for the random number generation. Can be used to repeat the same random sequence. (Note though that also some actions and the system itself uses random numbers.)
random_get_seed() Returns the current seed.
randomize() Sets the seed to a random number.
choose(val1,val2,val3,...) Returns one of the arguments choosen randomly. The function can have up to 16 arguments.
abs(x) Returns the absolute value of x.
sign(x) Returns the sign of x (-1, 0 or 1).
round(x) Returns x rounded to the nearest integer.
floor(x) Returns the floor of x, that is, x rounded down to an integer.
ceil(x) Returns the ceiling of x, that is, x rounded up to an integer.
frac(x) Returns the fractional part of x, that is, the part behind the decimal dot.
sqrt(x) Returns the square root of x. x must be non-negative.
sqr(x) Returns x*x.
power(x,n) Returns x to the power n.
exp(x) Returns e to the power x.
ln(x) Returns the natural logarithm of x.
log2(x) Returns the log base 2 of x.
log10(x) Returns the log base 10 of x.
logn(n,x) Returns the log base n of x.
sin(x) Returns the sine of x (x in radians).
cos(x) Returns the cosine of x (x in radians).
tan(x) Returns the tangent of x (x in radians).
arcsin(x) Returns the inverse sine of x.
arccos(x) Returns the inverse cosine of x.
arctan(x) Returns the inverse tangent of x.
arctan2(y,x) Calculates arctan(Y/X), and returns an angle in the correct quadrant.
degtorad(x) Converts degrees to radians.
radtodeg(x) Converts radians to degrees.
min(val1,val2,val3,...) Returns the minimum of the values. The function can have up to 16 arguments. They must either be all real or all strings.
max(val1,val2,val3,...) Returns the maximum of the values. The function can have up to 16 arguments. They must either be all real or all strings.
mean(val1,val2,val3,...) Returns the average of the values. The function can have up to 16 arguments. They must all be real values.
median(val1,val2,val3,...) Returns the median of the values, that is, the middle value. (When the number of arguments is even, the smaller of the two middle values is returned.) The function can have up to 16 arguments. They must all be real values.
point_distance(x1,y1,x2,y2) Returns the distance between point (x1,y1) and point (x2,y2).
point_direction(x1,y1,x2,y2) Returns the direction from point (x1,y1) toward point (x2,y2) in degrees.
lengthdir_x(len,dir) Returns the horizontal x-component of the vector determined by the indicated length and direction.
lengthdir_y(len,dir) Returns the vertical y-component of the vector determined by the indicated length and direction.
is_real(x) Returns whether x is a real value (as opposed to a string).
is_string(x) Returns whether x is a string (as opposed to a real value).