2010

Table Of Contents
Lesson 2: Conditional expressions
Introduction
Conditional statements set one attribute or variable for an expression based
on the condition of another attribute or variable. This means that when a
particular defined condition exists for one attribute then another attribute is
changed based on how the expression defines it to do so.
In this lesson you learn how to:
Use conditional statements to control an expression.
Refine the conditional statements using if and else statements.
Creating a conditional expression
In the following steps, you create a default sphere and write an expression to
increase its Scale Y attribute based on the animation playback time. In the
first two seconds of the animation time, Scale Y increases with the value of
the time. At two seconds and thereafter, Scale Y no longer increases.
To create an expression using conditional statements
1 Make sure youve done the steps in
Preparing for the lessons on page 626.
2 Create a NURBS or polygonal sphere at the origin with an X scale, Y scale,
and Z scale of 1.
3 Name the sphere Balloon.
4 Go to the start time.
5 With Balloon selected, choose Window > Animation Editors > Expression
Editor.
6 Enter this expression:
if (time < 2)
Balloon.scaleY = time;
This expression is an if statement. The if keyword causes the expression
to make a decision based on a comparison of two or more items. In this
case, the expression compares the value of time to the value 2.
634 | Chapter 12 Expressions