Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions something weird happens when i try to else if statment.

  • something weird happens when i try to else if statment.

    Posted by Assaf Goldlust on May 13, 2018 at 12:27 pm

    i tried to experiment with multiple conditional
    if/else statment.

    at first i tried this expression

    T=Math.floor(time);
    R=thisLayer.rotation;
    if(T>=3){[300,300]} else if (T>3&&R>10){[500,500]} else {[100,100]}

    its seems to be ok except that im not able to get the “[500,500] even when time is bigger then 3 seconds and
    and rotation is bigger then 10

    and then i tried to reverse the expression:

    T=Math.floor(time);
    R=thisLayer.rotation;
    if(R>10&&T>=3){[500,500]} else if (T>3){[300,300]} else {[100,100]};

    and its works. any ideas why?

    Assaf Goldlust replied 8 years ago 3 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    May 13, 2018 at 4:27 pm

    In the first one, if T is greater than 3, the first condition is met so it stops checking.

    Another way to structure it would be like this:


    if (T > 3){
    if (R > 10){
    [500,500];
    }else{
    [300,300];
    }
    }else{
    [100,100];
    }

    Dan

  • Assaf Goldlust

    May 13, 2018 at 4:49 pm

    i tried something semilar earlier that day.
    (in the sense off placing to “if” conditions)

    but it didnt work as i expected

    if(T>=3){[300,300]}
    if (T>3&&R>10){[500,500]} else {[100,100]}

    but as if he is ignoring the first condition why?

  • Kalleheikki Kannisto

    May 13, 2018 at 4:57 pm

    It is not ignored, but the result from the second line overrides the result from line one.

    Kalleheikki Kannisto
    Senior Graphic Designer

  • Dan Ebberts

    May 13, 2018 at 4:59 pm

    It will execute the first statement, but then, no matter the result of the first statement, it will always execute the second statement which will overwrite the result of the first statement.

    Dan

  • Assaf Goldlust

    May 13, 2018 at 5:13 pm

    ok thanks!

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