User Guide

Using Help | Contents | Index Back 324
Adobe After Effects Help Using Motion Math (PB only)
Using Help | Contents | Index Back 324
If the condition is true, Motion Math executes the statement before the else clause. If the
condition is false, Motion Math executes the statement after the else clause. In the
following example, if the current time is less than 0.5, Motion Math creates a scale
keyframe with a value of 0.3. If the current time is equal to or greater than 0.5, then Motion
Math creates a scale keyframe with a value of 1.5:
if (time() < 0.5)
value(solid_1, scale) = 0.3;
else
value(solid_1, scale) = 1.5;
The condition inside the parentheses must contain logic operators, which are described in
“Logical operations (use If statements) (PB only)” on page 332. To create compound logical
statements, you can use the logical operators for AND, OR, and NOT. To compare values,
you must use the == operator. In the following example, the time must equal 1 second for
the first statement to be evaluated:
if (time () == 1)
statement;
else
statement;
Because Motion Math runs an entire script multiple times at the specified sampling rate,
you may need to use the If statement to set parameters at the beginning of the work area,
as shown in the following example:
if (time () == start_time)
statement;
else
statement;
The statement before the else clause can set an initialization value; statements after the
else clause create motion or effects.
In some cases, you may not need to use the else clause. Without an else clause, the
statement immediately following the if clause is executed if the condition is true, and is
not executed if the condition is false.
Loops (PB only)
Although Motion Math runs a script using a built-in loop specified by the sampling rate,
you can also include loops inside scripts, using the following format:
while (expression) {
statement;
}
Statements contained inside the braces are repeatedly evaluated until the expression is no
longer true. In the following example, the loop cycles through each layer in the compo-
sition, creating a scale keyframe with a value of 35:
n = 1;
while (n <= num_layers) {
value(n, scale) = 35;