Zum Hauptinhalt springen

Math Expressions

The Evaluate Math Expression and If Math Expression events as well as any events supporting Script Values allow mathematical expressions to be used for performing calculations.

If Math Expression
Expression
e.g. $health >= 0...
True
Add Event
Else
False
Add Event

Expressions allow you to use many mathematical operations such as:

  • + add
  • - subtract
  • * multiply
  • / divide
  • == equal to
  • != not equal to
  • >= greater than or equal to

You are also able to use the following functions:

  • min(a, b) return the minimum of two values a and b
  • max(a, b) return the maximum of two values a and b
  • abs(a) return the absolute value of a
  • atan2(a, b) return the 2-argument arctangent of a and b
  • isqrt(a) return the square root of a rounded down to nearest integer
  • rnd(a) return a random number greater than 0 and less than a

You can use variables in expressions by typing $ and searching for the variable's name.

When you want to combine multiple conditions in your code, you can use boolean logic operators:

  • || or: This operator is used when you want to check if at least one of the conditions is true.
    For example, if you write $Local0 == 0 || $Local1 == 0, it means "if either variable Local0 equals 0 or variable Local1 equals 0".

  • && and: This operator is used when you want to check if all conditions are true. For example, if you write $Local0 == 0 && $Local1 == 0, it means "if both variable Local0 equals 0 and variable Local1 equals 0".

  • ! not: This operator is used when you want to invert the truth value of a condition.
    For example, if you write !($Local0 == 0), it means "if variable Local0 does not equal 0".