Skip to content

Operators

Operators allow the expression writer to perform mathematical operations on numbers, compare values, and work with variables within an expression.

There are standard expressions used by many programming languages which are available in Designer expressions. This page provides an overview and brief description of the available operators.

Comparison operators are useful when working with Logic functions.

  • less < - (a < b) returns true if a is strictly less than b
  • less equal <= - (a <= b) returns true if a is less than or equal to b
  • greater > - (a > b) returns true if a is strictly greater than b
  • greater equal >= - (a >= b) returns true if a is greater than or equal to b
  • not equal != - (a != b) returns true if a is not equal to b
  • equal == - (a == b) returns true if a is exactly equal to b

Note that for non-integer numeric values (i.e. floating point values) comparisons can be surprising. When comparing floating point values, consider reworking the comparison to be fuzzier. For example, a == b could be rewritten to be abs(a-b) < 0.01 which ensures that even if there is a tiny difference between the numbers, the comparison does what the expression writer would expect.

The comparison operators also work on text (string) values. == and != compare two strings by their exact contents, while <, >, <= and >= compare them alphabetically (lexicographically). For example, "apple" < "banana" returns true.

Text and numbers cannot be compared with each other. An expression such as "5" == 5 results in an error, as there is no automatic conversion between the two. Text values also only support the comparison operators. Arithmetic operators such as + cannot be used to combine strings.

This is useful for reacting to incoming text, such as a string sent to an OSC address. For example, if(osc:.address == "go", 1, 0) returns 1 when the value received at the OSC address /address is the text go, and 0 otherwise.

The logical not operator is useful when working with Logic functions.

  • not ! - (!a) flip the truth value of the variable or sub-expression following the operator (true->false, and false->true)

The index operator allows indexing into arrays of data.

  • square brackets - [] - (array[i]) returns the ith value within the array variable

It is also possible to index into arrays using negative indexes - array[-1] would select the last item in the array, and array[-2] would select the second from last. Note that the array must contain enough elements to support this, otherwise the expression will result in an error.

Arithmetic operators allow the writer to combine numeric values within expressions using common arithmetic operations.

  • addition - + - (a + b) returns the sum of a and b
  • subtraction - - - (a - b) returns the result of subtracting b from a
  • multiplication - * - (a * b) returns the product of a and b
  • division - / - (a / b) returns the quotient of a divided by b
  • modulus - % (a % b) returns the remainder of a divided by b