Operators

Operators

> Tutorial

Operators

Operators let you perform mathematical calculations and all kinds of data manipulation.

Here are the main operators:

In an expression with several operators, the operators are applied from left to right, following the natural precedence rules, such as * taking precedence over +.

Example with different operators:

You can also use parentheses, as in: (5 + 7) * 2.

Assignment operators

Besides the = operator, there are many assignment operators such as +=, -=, *= etc., which combine a calculation and an assignment.

An example with *=, which performs a multiplication and stores the result in the same variable:

A smarter healing condition

Our current healing condition makes us heal as soon as we have lost 1 life point. We can improve it by healing only when our life is below 75%:

To display the value of a variable or an expression in the fight actions, use the standard function debug(). Example: debug(getTotalLife() * 0.75).

❓ Quiz

What is the result of the code 10 + (5 * 7) - 20 / 4?

40 25 18 -30

What is the value of x at the end of the code var x = 10 x *= 2 x += 5 x /= 5?

5 15 22 12

What is the result of the code (true and false) or (true and true)?

1 3 true false

Complete AI