Monday, July 31, 2006

Lesson 4 : If/Else

In previous topics, we've covered some basic ways to define or modify parameters using After Effects expressions. But let's do something a little more complex to start harnessing the practical side of expressions.

What we discussed in prior topics was how to create some values based on time, or index. But, these values were always absolute. There is nothing telling After Effects that "if this value reaches a certain point, then do something else". This is exactly what if/else is for.

Consider the following example. Put this on the position of, perhaps, a type layer.

xPos= time * 200 ; yPos = position[1] ;

[ xPos , yPos ]

If you've been reading the other blogs, this should mostly make sense, but let's review.

We declare a variable "xPos" to be equal to time multipied by 200. Remember, time is the current time of the AE playback head or "CTI". As the time in the comp time becomes greater, the value of the term time increases. Therefore, as time in the comp progresses, the text moves in a postive direction in the X axis.

Next, we provide AE with the values that we want our position to be. Unlike parameters like opacity that are defined by one number, position is defined by multiple numbers (x and y, in this case), which we call an array. When we provide AE with the values for an array, we need to use this kind of format:

For a 2d layer:

[ x , y ]

or for a 3D layer:

[ x , y, z ]

So in our example, [ xPos , yPos ] is providing the x and y values.

xPos =========> is X

yPos =========> is Y

position[1] is just like value[1] that we've covered before, just specific to position. So, position[1] is the exisiting Y value that you can modify.

What were we talking about? Oh yeah, if/else.

What if we wanted this movement to stop at, say, a value 200 in the x axis?

In plain English (as that is what I speak), I would say:

"If the position of my object is less than 200, then keep moving, otherwise stop".

The way we say this in expressions is like this:

if (condition){ result1 }else{ result2 }

AE will not even look at anything beyond line result1 if the condition is true. When condition is not true, AE will ONLY be concerned with result2. It's always going to look at result1 OR result2, never both with if/else.

So, for this to work with our example, this would be the code:

xPos= time * 200 ;

yPos = value[1] ;

if (xPos < 200){

[xPos, yPos];

}else{ [200 , yPos ] ; }

Let's take this apart. First we declare our variables:

xPos= time * 200 ; yPos = value[1] ;

Then we have:

if (xPos < 200){

which means: If the condition of xPos being less than 200 is true... then the result is:

[ xPos , yPos ];

However, if it is not true..

}else{

Then set the x position equal to 200, and y position to yPos:

[200 , yPos ] ;

Then close the brace:

}

As xPos increases, our type's x position increases. When xPos is over 200, the type's x-position becomes fixed at 200.

You might be a little overwhelmed by a lot of things that look unfamiliar, like these { and } braces. When using an if/else condition, we have two possible results: if the condition is true do result1, else do result2. Both of the results must be enclosed with these { } braces, even if on different lines. We can right this several ways, like:

if (condition)

{result1}

else

{result2}

But, the first way of writing it is more common, as result1 and result2 are not limited to one line of code, they could be a complex computation, and becomes easier to view if the brackets are pushed out of the way. ALWAYS REMEMBER.. never put one brace { without closing it with another brace }.

Give that a try and check back for more expression topics!

21 Comments:

Blogger El Oso said...

This blog is fantastic! I'm actually understanding and retaining the information presented here.

If you packaged this into a complete book, I'd buy it in a heartbeat.

5:56 PM  
Blogger Harry said...

Mmmmmaaaybe just maybe some video training is coming.

7:49 PM  
Blogger Unknown said...

Thank you so much! This is the most well written stuff sbout expressions I have seen so far on any site!

7:05 AM  
Blogger Nate Bro said...

This really is a well written site. Even the user comments teach you something! I am planning on taking college courses in javascript programming, but as of right now am just a beginner. In the realm of amatures, there is no other tool quite so concise, informative, and correct as this blog! (Believe me. I checked) Thanks for all your work. :)

3:51 PM  
Blogger Unknown said...

I love your site! You will be in our prayers and thoughts! Nice and informative post on this topic thanks for sharing with us.Thank you


Logo Maker

5:29 AM  
Blogger laustan said...

Very nice article! nice to reading this post!!

best essay writing service company

12:20 AM  
Blogger Unknown said...

Very useful post actually your shared here.I am sure your post will help students more in their study. It helped me lot. Thank you.
best essay writing service

9:57 PM  
Blogger ciitnoida said...

Thanks for posting the useful information to my vision. This is excellent information.

Best BCA College in Noida

12:25 AM  
Blogger Unknown said...

myTectra Placement Portal is a Web based portal brings Potentials Employers and myTectra Candidates on a common platform for placement assistance

10:21 PM  
Blogger mohit said...

It's the best time to make some plans for the long run and it is time
to be happy.
instagram sign up
tutuapp apk ios

1:56 AM  
Anonymous Anonymous said...

Thanks for such a great article here. I was searching for something like this for quite a long time and at last I’ve found it on your blog. It was definitely interesting for me to read about their market situation nowadays. Well written article Thank You for Sharing with Us pmp training in chennai | pmp training institute in chennai | pmp training centers in chennai| pmp training in velachery | pmp training near me | pmp training courses online | project management courses in chennai

10:10 PM  
Blogger digitalsourabh said...

Big Data Hadoop Training in Bhopal
FullStack Training in Bhopal
PHP Training in Bhopal
Python Training in Bhopal
Machine Learning Training in Bhopal
Digital Marketing Training in Bhopal

4:38 AM  
Blogger Della said...

Unsur permainan Poker Uang Asli telah lama hadir dan mendunia lebih-lebih di kalangan para pecinta judi, masih banyak yang belum paham bagaimana sistem bermain pada game tersebut.
asikqq
http://dewaqqq.club/
http://sumoqq.today/
interqq
pionpoker
bandar ceme terpercaya
betgratis
paito warna terlengkap
syair sgp

2:41 PM  
Anonymous Anonymous said...

This comment has been removed by the author.

6:01 AM  
Blogger nader galal said...

شركه الصفرات من اضمن الشركات بالرياض على الاطلاق من حيث العماله وادوات واجهزه التنظيف ومواد العزل وادوات كشف التسريبات تمتلك الشركه افض انواع المنظفات المستورده شركه الصفرات فى خدمتك وخدمه اسرتك فى اى
.وقت كل ما عليك هو التواصل مع مندوبنا عبر الارقام الموضحه سيصك فريق العمل المتخصص بافضل المعدات لأداء الخدمه المطلوبه
شركة الصفرات لتنظيف المنازل بالرياض
شركة الصفرات لعزل الاسطح بالرياض
شركة الصفرات لتنظيف المجالس بالرياض
شركة الصفرات لتنظيف السجاد بالرياض
شركة الصفرات لنقل الاثاث بالرياض
شركة الصفرات لمكافحة الحشرات بالرياض
شركة الصفرات لكشف التسربات بالرياض
شركة الصفرات لتنظيف المسابح بالرياض
شركة الصفرات لتنظيف الخزانات بالرياض
شركة الصفرات لتسليك المجاري بالرياض

5:09 AM  
Blogger شركة خدمات منزلية said...

شركة نقل اثاث بابها
كيف تختار أثاث مكتبي

عند القيام بعملية اختيار أثاث مكتبي يجب أن تعرف بعض الخطوات التي تساعدك في الوصول لأعلى كفاءة تناسب ذوقك ومكانك ومن هذة الخطوات
شركة نقل اثاث بابها
قياس المساحة المطلوبة للمكان : فالمساحة عامل مهم جدا عند اختيارك لأثاث مكتبي منظم ومرتب وهذة الخطوة مهمة حتى لا يكون المكان مزدحم والأثاث مزدحم ويكون غير مرتب مع بعضه البعض من هنا نقول أن الرسم التخطيطى المبدأى للمكان يساعدك فى عوامل كثيرة ,وذلك لأنك تكون على دراية كاملة بمقاسات الأثاث الذى ستقوم بوضعه فى مكتبك ,أو شركتك
شركة نقل اثاث بابها
الألوان :تعتبر الألوان من أهم الخطوات التي يجب اتباعها عند اختيار أثاث مكتبي وذلك لعدة عوامل من أهمها تنسيق الأثاث مع الدهانات التي تكون بالمكتب وذلك لأظهاره بشكل مناسب ولائق ومن هنا نقول أن تنسيق الألوان الدهان مع الأثاث يعتبر من الأساسيات شركة نقل عفش بابها,ولايمكن إهمال هذه الخطوة ,وعليك بالألوان البسيطة لأنها تكون عصرية وتظهر الملامح الكاملة للديكورات التى قمت بعملها فى مكتبك شركة نقل عفش بابها

12:06 PM  
Blogger Dodit Tamko said...

Oh my goodness! an amazing article dude. Thank you However I am experiencing issue with ur rss. Don’t know why Unable to subscribe to it. Is there anyone getting identical rss problem? Anyone who knows kindly respond. Thnkx

iMuslim.co.id
Fasion Muslim
Muslim Beauty

3:40 AM  
Blogger Laura Hilaca said...

Very nice post, i certainly love this website, keep on it

Libur.co
Ayo Liburan
Tempat Liburan

7:07 PM  
Blogger Mozila Pandawa said...

You should take part in a contest for one of the best blogs on the web. I will recommend this site!

Jogja
Wisata Jogja
Yogyakarta

5:20 PM  
Blogger Irene Berry said...

You made some decent points there. I looked on the internet for the issue and found most individuals will go along with with your website.

Provenexpert.com
Information
Click Here
Visit Web

1:23 AM  
Anonymous Anonymous said...

Impressive writing. You have the power to keep the reader occupied with your quality content and style of writing. I encourage you to write more.

BCom 3rd Year Admit Card

12:06 AM  

Post a Comment

<< Home