Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Multiple IF statements syntax question

  • Multiple IF statements syntax question

    Posted by Joel Bellagamba on September 19, 2017 at 9:48 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.

    Mahdi Mehrabi replied 5 years, 1 month ago 4 Members · 5 Replies
  • 5 Replies
  • Kevin Camp

    September 19, 2017 at 11:09 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

  • Dan Ebberts

    September 19, 2017 at 11:19 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

  • Joel Bellagamba

    September 20, 2017 at 8:17 am

    Many thanks, Dan. This code worked a treat!

    Simon

  • Joel Bellagamba

    September 20, 2017 at 8:20 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

  • Mahdi Mehrabi

    March 26, 2021 at 10:36 am

    Hello there

    I want to use multiple if with a checkbox controller. when the first checkbox is checked, first if works.

    for the second checkbox, I have another if statement.

    and finally, for the third checkbox, I will have another if statement.

    How can I do this kind of expression?

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy