ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Multiple IF statements syntax question

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Simon Brough
Multiple IF statements syntax question
on Sep 19, 2017 at 9:48:15 pm

Can anyone help with some IF statement syntax? No errors are shown, but this just doesn't seem to work, to control whether an object comes in from left, top, right or bottom based on a slider (1-4):

if (comp("ObjectControl").layer("Control").effect("Direction")("Slider")==1) {
horiz=3050}
if (comp("ObjectControl").layer("Control").effect("Direction")("Slider")==3) {
horiz=-3050}
if (comp("ObjectControl").layer("Control").effect("Direction")("Slider")==2) {
vert=2550}
if (comp("ObjectControl").layer("Control").effect("Direction")("Slider")==4) {
vert=-2550}
else{
horiz=0
vert=0
}

[easeOut(time,inPoint,inPoint+1, value[0]+horiz, value[0]),ease(time,inPoint,inPoint+1,value[1]+vert,value[1])]


I'm sure it's the IF statements, as using:

horiz=3050;
vert=2250;
[easeOut(time,inPoint,inPoint+1, value[0]+horiz, value[0]),ease(time,inPoint,inPoint+1,value[1]+vert,value[1])]


achieves a result, albeit just one of the four I need.


Return to posts index

Kevin Camp
Re: Multiple IF statements syntax question
on Sep 19, 2017 at 11:09:41 pm

i think you want to use else if... but you're also missing some semicolons at the end of each line.

if (comp("ObjectControl").layer("Control").effect("Direction")("Slider")==1) horiz=3050;
else if (comp("ObjectControl").layer("Control").effect("Direction")("Slider")==3) horiz=-3050;
else if (comp("ObjectControl").layer("Control").effect("Direction")("Slider")==2) vert=2550;
else if (comp("ObjectControl").layer("Control").effect("Direction")("Slider")==4) vert=-2550;
else{
horiz=0;
vert=0;
}

[easeOut(time,inPoint,inPoint+1, value[0]+horiz, value[0]),ease(time,inPoint,inPoint+1,value[1]+vert,value[1])]


Kevin Camp
Art Director
KCPQ, KZJO & KRCW


Return to posts index

Simon Brough
Re: Multiple IF statements syntax question
on Sep 20, 2017 at 8:20:09 am

Thanks for taking a look, Kevin.

This gave me an expression error, unfortunately. Though, Dan has supplied a re-write (below) which works.

Simon


Return to posts index


Dan Ebberts
Re: Multiple IF statements syntax question
on Sep 19, 2017 at 11:19:59 pm

I think I'd do it like this:


horiz=0;
vert=0;
d = comp("ObjectControl").layer("Control").effect("Direction")("Slider").value;
if (d==1) horiz=3050
else if (d==3) horiz = -3050
else if (d==2) vert = 2550
else if (d==4) vert = -2550;
offset = easeOut(time,inPoint,inPoint+1, [horiz,vert],[0,0]);
value + offset



Dan



Return to posts index

Simon Brough
Re: Multiple IF statements syntax question
on Sep 20, 2017 at 8:17:39 am

Many thanks, Dan. This code worked a treat!

Simon


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]