Products Applications Downloads Features Wiki forum Store

Expression

From Wiki077
Jump to: navigation, search

Expressions in TouchDesigner are functions where you pass it data (string, float, vector etc.) and it returns data (not necessarily the same type as the data passed in). Examples:

  • sqrt(16) takes a number and returns a number, 4.
  • strlen("hello") takes a string and returns a number, 5.
  • base("flower42") is a "string expression" - takes a string and returns a string, flower.
  • if($F>10,2,3) takes numbers and returns a number.
  • ifs($F>10,"high","low") takes a mix of numbers and strings, returning a string.
  • tab("guests",2,3) gets the string in the third row, 4th column of the table guests.
  • chop("/project1/constant1/chan1") gets the channel named chan1 in the CHOP /project1/constant1.

Expressions are used in Parameters, DATs (especially the Evaluate DAT), Commands and Scripts.

A complete listing of all expressions is in the Expressions category.

Alternately select Commands and Expressions from the main Help menu, or type exhelp in the textport.

Back-quotes

An important concept to understand when using expressions is when to use back-quotes (`). The back-quote key is same key as the Tilde (~) key. It's usually found in the upper-left corner of the keyboard.

Placing something in backquotes tells TouchDesigner that the enclosed string is an expression that should be evaluated.

`expression(parameter)`

You need to place back-quotes around an expression if it's being used in a place where TouchDesigner is usually expecting a string. For example an expression in a string parameter like the Text TOP's Text parameter needs to be enclosed in back-quotes. However an expression in a numeric parameter like the Geometry object's Translate parameter does not need back-quotes, because TouchDesigner expects either a number, or an expression in that parameter.

You must always enclose expressions in scripts and when entering commands in the textport. E.g

echo sine of 45 degrees is `sin(45)`
Personal tools