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
Section titled “Comparison operators”Comparison operators are useful when working with Logic functions.
- less
<- (a < b) returns true ifais strictly less thanb - less equal
<=- (a <= b) returns true ifais less than or equal tob - greater
>- (a > b) returns true ifais strictly greater thanb - greater equal
>=- (a >= b) returns true ifais greater than or equal tob - not equal
!=- (a != b) returns true ifais not equal tob - equal
==- (a == b) returns true ifais exactly equal tob
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.
Comparing text
Section titled “Comparing text”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.
Logical operator
Section titled “Logical operator”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)
Index operator
Section titled “Index operator”The index operator allows indexing into arrays of data.
- square brackets -
[]- (array[i]) returns theith value within thearrayvariable
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
Section titled “Arithmetic operators”Arithmetic operators allow the writer to combine numeric values within expressions using common arithmetic operations.
- addition -
+- (a + b) returns the sum ofaandb - subtraction -
-- (a - b) returns the result of subtractingbfroma - multiplication -
*- (a * b) returns the product ofaandb - division -
/- (a / b) returns the quotient ofadivided byb - modulus -
%(a % b) returns the remainder ofadivided byb