Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression to return last value when Checkbox is enabled

  • Expression to return last value when Checkbox is enabled

    Posted by Jacob Roth on June 21, 2018 at 1:01 pm

    Hi everybody,

    So I’m trying to combine solutions from Dan Ebberts and it’s not working so far.

    I have the falling leaf effect that Dan wrote here:

    https://www.aenhancers.com/viewtopic.php?t=8

    And I’m trying to combine it with his code to return the last expression value at time here:

    https://forums.creativecow.net/thread/227/34463

    It’s not really working, and I don’t know how to fix it. The code I’ve attached is on position.

    Any ideas?

    yVelocity = 200; //pixels per second
    oscFreq = thisComp.layer("Null 1")("Effects")("Oscillation Frequency")("Slider"); //oscillations per second
    oscDepth = 35; //oscillation depth (pixels)
    drift = 25; // drift (wind?) (pixels per second: - = left, + = right)
    chkBx = thisComp.layer("Null 1")("Effects")("Stop")("Checkbox");
    n = 0;

    if (chkBx.numKeys > 0){
    n = chkBx.nearestKey(time).index;
    if (chkBx.key(n).time > time) n--;
    }
    t = 0;
    curTime = time;
    if (n > 0){
    for (i = n; i > 0; i--){
    if (chkBx.key(i).value > 0){
    t += (curTime - chkBx.key(i).time);
    }
    curTime = chkBx.key(i).time;
    }
    if ((curTime > 0) && (chkBx.key(1).value > 0)) t += curTime;
    }else{

    value + [oscDepth*Math.sin(oscFreq*Math.PI*2*time) + drift *time,
    yVelocity*time,0]
    }

    Jayden Bradley replied 7 years, 11 months ago 3 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    June 21, 2018 at 1:19 pm

    I think what you need to do is replace time in falling leaf expression with the t variable calculated in the checkbox expression, like this:


    yVelocity = 200; //pixels per second
    oscFreq = thisComp.layer("Null 1")("Effects")("Oscillation Frequency")("Slider"); //oscillations per second
    oscDepth = 35; //oscillation depth (pixels)
    drift = 25; // drift (wind?) (pixels per second: - = left, + = right)
    chkBx = thisComp.layer("Null 1")("Effects")("Stop")("Checkbox");
    n = 0;

    if (chkBx.numKeys > 0){
    n = chkBx.nearestKey(time).index;
    if (chkBx.key(n).time > time) n--;
    }
    t = 0;
    curTime = time;
    if (n > 0){
    for (i = n; i > 0; i--){
    if (chkBx.key(i).value > 0){
    t += (curTime - chkBx.key(i).time);
    }
    curTime = chkBx.key(i).time;
    }
    if ((curTime > 0) && (chkBx.key(1).value > 0)) t += curTime;
    }else{
    if (chkBx.value > 0) t = time;
    }

    value + [oscDepth*Math.sin(oscFreq*Math.PI*2*t) + drift*t,
    yVelocity*t,0]

    Dan

  • Jacob Roth

    June 21, 2018 at 1:34 pm

    Yep, that did it.

    How translatable is the checkbox control for pausing an expression to other types of expressions. Like, if I want to be able to pause a wiggle?

  • Dan Ebberts

    June 21, 2018 at 3:32 pm

    You would just need to use t for wiggle’s 5th parameter (time):


    chkBx = thisComp.layer("Null 1")("Effects")("Stop")("Checkbox");
    n = 0;

    if (chkBx.numKeys > 0){
    n = chkBx.nearestKey(time).index;
    if (chkBx.key(n).time > time) n--;
    }
    t = 0;
    curTime = time;
    if (n > 0){
    for (i = n; i > 0; i--){
    if (chkBx.key(i).value > 0){
    t += (curTime - chkBx.key(i).time);
    }
    curTime = chkBx.key(i).time;
    }
    if ((curTime > 0) && (chkBx.key(1).value > 0)) t += curTime;
    }else{
    if (chkBx.value > 0) t = time;
    }

    wiggle(1,100,1,.5,t)

    Dan

  • Jacob Roth

    June 21, 2018 at 5:46 pm

    Dan you’re blowing my mind. I didn’t even know there were third and fourth parameters to the wiggle expression. What do they control?

  • Dan Ebberts

    June 21, 2018 at 6:13 pm

    They control number of octaves and the influence of each octave in the noise wave, allowing you to make the wiggle more frenetic. I don’t think I’ve ever used them, except to get to the time parameter.

    Dan

  • Jayden Bradley

    August 15, 2018 at 3:39 pm

    Hey, guys. Helpful information so far, however, i would like some help as to how to translate this time/t for other expressions. For e.g overshoot by Dan.

    freq = 2;
    decay = 5;
    delay = .15;
    dur = .12;

    myDelay = (textIndex-1)*delay;
    t = time - (inPoint + myDelay);
    startVal = 100;
    endVal = 0;

    if(t < dur){
    linear(t,0,dur,startVal,endVal);
    }else{
    amp = (endVal - startVal)/dur;
    w = freq*Math.PI*2;
    endVal + amp*(Math.sin(t*w)/Math.exp(decay*t)/w);
    }

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