Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Add a loop after a if?

  • Add a loop after a if?

    Posted by Ricardo Martins on November 29, 2021 at 11:50 pm

    Hey guys, I’m trying to make a character blink with a -50 to +50 slider, and also I have a dropdown menu that would modify that to be like from 0 to +50.

    That part is working but, I also would like to make those keyframes to loopOut(“clycle”)
    Is there a way add that on this code:

    d = thisComp.layer(“ctrl”).effect(“Dropdown Menu Control”)(“halfblink”);

    x = value[0];

    if (d ==2)

    m=linear(x, -50,50,0,50);

    else

    m = x;

    [m,0];

    Tks in advance

    Ricardo Martins replied 4 years, 8 months ago 2 Members · 3 Replies
  • 3 Replies
  • Andrei Popa

    November 30, 2021 at 8:48 am

    Hi Ricardo.

    If you have only 2 keyframes, this should work.

    d = 2;
    t1 = key(1).time;
    t2 = key(2).time;
    x = valueAtTime(((time - t1) % 2) + t1)[0];
    m = d == 2 ? linear(x, -50, 50, 0, 50) : x;
    [m, 0];

    If you have more keyframes, you should change the values for t1 and t2 to be the time of the second-last and last keyframes.

    I modified your if statement into a ternary operator for faster execution.

  • Ricardo Martins

    November 30, 2021 at 2:49 pm

    Always saving me Andrei, thank you very much!

    Also I tested here and actually independent of how many keys I have, just keeping the key(1) and key(2) as you did works better than just the last 2 ones.

    BTW I started the ukramedia expression course you recommended. That is really pretty good, changed my life, tks again.

  • Ricardo Martins

    November 30, 2021 at 3:20 pm

    Also, never going to use if statement again

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