Skip to content

Latest commit

 

History

History
152 lines (102 loc) · 4.6 KB

12.-math.md

File metadata and controls

152 lines (102 loc) · 4.6 KB

12. Math

Operators

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:

Prefix

  • There is only one operand and the operator is before the operand.

Prefix

Infix

  • There are two operands and the operator is between the operands.

Infix

Postfix

  • There is only one operand and the operator is after the operand.

Postfix

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.

Operator List

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]

Query

  • ?
  • The ? operator checks if a logic value is true.
  • [Postfix] : [9]
  • ex. BossDefeated?

Not

  • not
  • The not operator negates the success or failure of an expression.
  • [Postfix] : [8]
  • ex. not BossDefeated?

Positive (+)

  • +
  • 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

Negative (-)

  • -
  • You can use the operator - as a prefix to a number to negate the number value.
  • [Prefix] : [8]
  • ex. -MyScore

Multiplication (*)

  • *
  • The * multiplies two number values together.
  • [Infix] : [7]
  • ex. MyScore * ScoreMultiplier

Division (/)

  • /
  • The / operator divides the first number operand by the second number operand. Integer division is failable.
  • [Infix] : [7]
  • ex. MyScore / ScorePenalty

Addition (+)

  • +
  • The + operator adds two number values together. When used with strings and arrays, the two values are concatenated.
  • [Infix] : [6]
  • ex. MyScore + ScoreBonus

Subtraction (-)

  • -
  • The - operator subtracts the second number operand from the first operand
  • [Infix] : [6]
  • ex. MyScore - ScorePenalty

Addition Assignment (+=)

  • 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

Subtraction Assignment (-=)

  • 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

Multiplication Assignment ( *= )

  • 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

Division Assignment (/=)

  • 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

Equal to (=)

  • =
  • The = operator succeeds when the left operand is equal to the right operand. Fails otherwise
  • [Infix] : [4]
  • ex. MyScore = HighScore

Not Equal to ( <>)

  • <>
  • The <> operator succeeds when the left operand is not equal to the right operand. Fails otherwise
  • [Infix] : [4]
  • ex. MyScore <> HighScore

Less than ( < )

  • <
  • The < operator succeeds when the left operand is less than the right operand. Fails otherwise.
  • [Infix] : [4]
  • ex. MyScore < HighScore

Less than or equal to ( <= )

  • <=
  • The <= operator succeeds when the left operand is less than or equal to the right operand. Fails otherwise.
  • [Infix] : [4]
  • ex. MyScore <= HighScore

Greater than ( > )

  • >
  • The > operator succeeds when the left operand is greater than the right operand. Fails otherwise.
  • [Infix] : [4]
  • ex. MyScore > HighScore