Writing Expressions

Expressions are based on a JavaScript (JS) program. You can access to the full capability of the JS language and write any type of program, as long as it executes relatively quickly.

The entire JavaScript must be defined within the expression code. There are no common repository of JS functions and services available to the expression column scripting environment. However, with the Harmony C++ SDK, you can extend the API of functions available to the expression scripting environment.

If you are working with an old project that contains expressions, they are converted to a JS program. Only simple expressions are updated. Complex expression and expressions using non-ported services cannot be converted. For these type of expressions, you must convert them manually.

Expression Editor

The Expression editor is where you write expressions. It is a simple text editor that can handle incomplete or invalid JS programs although they will not be evaluated, Harmony can save and load invalid JS programs.

The Expression editor evaluates the current script at the current global frame and reports any error or returns the numerical result of the program.

Expression JavaScript Program

An expression JavaScript program can be any valid program. The only requirement is the last statement of the script must leave a number on the stack. The “return” statement is NOT need as the script is not a function.

Valid expression column JS program

Example 1

10

This is a trivial program returning 10.

Example 2

currentFrame

This is another trivial program returning the current frame. The variable “currentFrame” is one of the predefined variables and services available.

Example 3

value( “MyBezierFunction”, currentFrame - 1 );

A simple expression program the returns the value of the Bezier function “MyBezierFunction” at the previous frame. If this function does not exist in the scene, the expression column will be blank in the XSheet. If this function does exist, the expression column will show the value of that function at the frame.

Example 4

This is another not so trivial program that evaluates the fibonacci series starting at the current frame. The value will be computed up to a certain current frame. After that frame, the program is too complex and will be stopped by the engine before finishing.

Errors

Programs that take too long to execute, do not generate a numerical value, or has syntax errors will not be compiled and will not compute a value. The scripting editor will show the condition that triggers this, but the Xsheet will simply display a blank field.