If statements (PB only)Use If statements to create a conditional portion of the script, which Motion Math executes only if a specified condition is true or false. The If statement uses the following format: if (condition) statement; else statement; You can also include multiple statements inside the If statement, using braces to group them: if (condition) { statement 1; statement 2; } else { statement 3; statement 4; } 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). 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. |