Game Maker Programming/Mathematical calculations
Game Maker can perform mathematical functions on integers, on variables containg integers. Writing in code:
2*2
would equal 4. If a=2, then:
a*a
would also equal 4. Game Maker can perform basic addition, multiplication, subtraction and division, as well as square rooting, as shown below:
sqrt(integer);
random(x) | Random decimal number between 0 and x (including 0, but not x). |
random_range(x,y) | Random decimal number between x and y (including x, but not y). |
abs(x) | Absolute value of x. |
sign(x) | Sign of x (-1, 0, or 1) |
round(x) | Round to nearest integer. (.5 rounds to nearest even.) |
floor, ceil(x) | Floor and ceiling functions. |
frac(x) | Returns fractional portion. |
sqrt(x) | Square root. |
power(x,n) | x^{n} |
exp(x) | e^{x} |
ln(x) | Natural log of x (log_{e} x) |
log2(x) | Log 2 of x. |
log10(x) | Log 10 of x. |
logn(n,x) | Log of base n of x. |
sin (x), cos(x), tan(x) | Sin, cos or tan of x. |
arcsin, arccos, arctan(x) | Inverse sin, cos or tan of x. |
arctan2(y, x) | arctan(y/x). returns angle in correct quadrant. |
degtorad(x), radtodeg(x) | Converts between degrees and radians. |
min(...), max(...), mean(...), median(...) | Returns min, max, mean or median of all arguments. |
point_distance(x1, y1, x2, y2) | Returns distance between two points. |
point_direction(x1, y1, x2, y2) | Returns direction from (x1, y1) to (x2,y2) in degrees. |
lengthdir_x(len, dir), lengthdir_y(len, dir) | Returns x or y component of the indicated length and direction. |