Assignment Operators

In osl you can use an assignment operator to set a variable to itself but modified by an operator. This allows you to compact code into a simpler format.

An example of an assignment operator is += where it adds/joins a value to the variable

variable = 10
// the variable is 10

variable += 10
// the variable is now 20

All Assignment operators

variable += number
// adds a number to the variable value

variable += string
// joins a string to the variable value

variable -= number
// subtracts a number from the variable value

variable /= number
// divides the variable value by a number

variable *= number
// multiplies the variable value by a number

variable %= number
// sets the varable value to "variable % number"

variable ^= number
// sets the varable value to "variable ^ number"

Increment/Decrement

variable ++
// increase a variable by exactly 1

variable --
// decrease a variable by exactly 1

Nullish Coalescence

Nullish Coalescence

variable ??= 10
// only sets the variable if the variable doesnt exist

Last updated