Skip to content

Expressions Overview

Expressions can be used to build dynamic behaviour and link parts of designer together. Expressions are evaluated every frame and result in “values” which are either numbers or text. The value is used in the context of the expression. For example, in layers the value is used to populate the property the expression is attached to.

Expressions are a small programming language which allows the user to build custom behaviours into the software.

They are used in a number of areas, such as layers and automation.

When you type in an expression, the property field turns green when the expression has been correctly understood. If there is a mistake, the property field turns red; moving the mouse over the property field will open up a text message telling you what went wrong.

Creating Expressions without writing code

It is possible to create some basic expressions which reference other parts of Designer by Creating a connection using mouse drag. This is the easiest way of getting started with expressions.

Expression syntax

Expressions mimic common syntax found in many programming languages. Expressions consist broadly of:

  • constants (a number like 123 or text such as "hello world".)
  • variables (a symbol e.g. my_value which refers to a value defined elsewhere.)
  • functions (a behaviour which generates a value from other inputs e.g. max(1, 2) which results in the higher value, 2.)
  • operators (a mathematical operator which performs arithmetic on values, e.g. + or -.)

There are a number of predefined functions and variables documented in the relevant locations.

It is also possible to define your own functions and variables by using an expression variables device or expression variables layer.

Expressions are case-sensitive, so a variables or functions called hello are distinct from another called HELLO or yet another called Hello, and so on.

Prefixes

Prefixes are used to alter the result of an overall expression. They take the form of a word, followed by two colon characters, followed by an expression, like so:

scale::<expression>

Apart from text formatting, below, layer expressions also use prefixes.

Text formatting

Text-type expressions may wish to forego mathematical evaluation and instead want to embed values within plain human readable language. It is possible to change the expression syntax from evaluating variables to ‘string interpolation’ scheme. This is a piece of text with placeholders. Upon evaluation, the placeholders are evaluated as expressions and formatted in-place in the text.

For example, the following expression is mostly text, but a dynamic expression is embedded within it. The focus changes from evaluation to presentation.

format::This is my information: The system has been running for {int(uptime / 60)} minutes and {int(uptime % 60)} seconds

Would result in

This is my information: The system has been running for 2 minutes and 15 seconds

Text formatting is documented here