12. Math
Last updated
Was this helpful?
Last updated
Was this helpful?
Operators are special functions defined in the Verse programming language to perform actions such as math operations on their operands. For example, in the expression 1 + 2
, the +
is an operator, and 1
and 2
are both operands.
There are three formats for operators that you’ll see in Verse:
There is only one operand and the operator is before the operand.
There are two operands and the operator is between the operands.
There is only one operand and the operator is after the operand.
This page describes all the operators you can use in Verse, how they work, and their order of evaluation when used in combination with other operators.
When multiple operators are used in the same expression, they are evaluated in the order of highest to lowest precedence. Below lists all built-in operators in Verse and their precedence.
[Operator Format]:[Operator Precedence]
?
The ?
operator checks if a logic
value is true
.
[Postfix] : [9]
ex. BossDefeated?
not
The not
operator negates the success or failure of an expression.
[Postfix] : [8]
ex. not BossDefeated?
+
You can use the +
or operator as a prefix to a number to help align your code visually, but it won't change the value of the number.
[Prefix] : [8]
ex. +MyScore
-
You can use the operator -
as a prefix to a number to negate the number value.
[Prefix] : [8]
ex. -MyScore
*
The *
multiplies two number values together.
[Infix] : [7]
ex. MyScore * ScoreMultiplier
/
The /
operator divides the first number operand by the second number operand. Integer division is failable.
[Infix] : [7]
ex. MyScore / ScorePenalty
+
The +
operator adds two number values together. When used with strings and arrays, the two values are concatenated.
[Infix] : [6]
ex. MyScore + ScoreBonus
-
The -
operator subtracts the second number operand from the first operand
[Infix] : [6]
ex. MyScore - ScorePenalty
set +=
With this operator, you can combine addition and assignment in the same operation to update a variable's value.
[Infix] : [5]
ex. set MyScore += ScoreBonus
set -=
With this operator, you can combine subtraction and assignment in the same operation to update a variable's value.
[Infix] : [5]
ex. set MyScore -= ScorePenalty
set *=
With this operator, you can combine multiplication and assignment in the same operation to update a variable's value.
[Infix] : [5]
ex. set MyScore *= ScoreMultiplier
set /=
With this operator, you can combine division and assignment in the same operation to update a variable's value, unless the variable is an integer.
[Infix] : [5]
ex. set MyScore /= ScorePenalty
=
The =
operator succeeds when the left operand is equal to the right operand. Fails otherwise
[Infix] : [4]
ex. MyScore = HighScore
<>
The <>
operator succeeds when the left operand is not equal to the right operand. Fails otherwise
[Infix] : [4]
ex. MyScore <> HighScore
<
The <
operator succeeds when the left operand is less than the right operand. Fails otherwise.
[Infix] : [4]
ex. MyScore < HighScore
<=
The <=
operator succeeds when the left operand is less than or equal to the right operand. Fails otherwise.
[Infix] : [4]
ex. MyScore <= HighScore
>
The >
operator succeeds when the left operand is greater than the right operand. Fails otherwise.
[Infix] : [4]
ex. MyScore > HighScore