Math

# Math

Math is easy in Game Maker, however, you must remember that you have to do something with the result of the math. You either need to display it or store it in a variable.

# Arithmetic

• var = 2 + 2
• var = var + 2
• var += 2
• var += var
• note that gamemaker does not have operations such as ++ or --, as possible in C

## Subtraction

• var = 2 - 1
• var = var - 2
• var -= 2
• var -= var

## Multiplication

• var = 2 * 2
• var = var * 2
• var *= 2 //not sure if supported
• var *= var //not sure if supported

## Division

It is mathematically impossible to divide a number by 0. Be careful when using variables as operands.

• var = 2 / 2
• var = var / 2
• var /= 2 //not sure if supported
• var /= var not sure if supported

## Order of Operations

The order of operations can be manipulated using parenthesis.

## Percentages

Percentages are decimal fractions.

# Math Tips

## Displaying the Results of Calculation

If you are just playing around with the math capabilities of Game Maker and want to see the results of your calculations as numbers, there are two ways to easy ways to do this. Both of them require you to convert the number to a string using the string() function :

1. Put the result of calculation in the room_caption :

``````math_result = 4 + 4;
room_caption = string(math_result);```
```

2. Display it using draw_text()

``````math_result = 4 + 4;
draw_text(10,10,math_result);```
```