Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Unable to get value at previous frame

  • Unable to get value at previous frame

    Posted by Joss Gitlin on February 9, 2021 at 3:23 pm

    Hey guys. Been browsing this forum for years, and now I finally have a question so I made an account.

    I have the expression read a variable (x) that has a different value every frame.
    x = thisComp.layer(“A_BASS”).effect(“Both Channels”)(“Slider”);

    if (x.valueAtTime(time) < 30) {
    valueAtTime(time-thisComp.frameDuration*time)-1;
    }
    else 100+(x/2);

    For some reason, the if statement generates a value of 100 any time its true (the expression controls the magnification value of the magnify effect, which happens to have a minimum value of 100). Even if the previous frame has a magnification value of 140, it still returns 100.

    Any idea what to do? All help appreciated

    Joss Gitlin replied 5 years, 6 months ago 3 Members · 8 Replies
  • 8 Replies
  • Dan Ebberts

    February 9, 2021 at 5:26 pm

    I’m not sure exactly what you’re trying to do, but this should get you the value of the property with the expression at the previous frame:

    valueAtTime(time-thisComp.frameDuration)

    Remember though, this will be the pre-expression value, not the value calculated by the expression at the previous frame. I apologize if you already knew that.

  • Fabrice Leconte

    February 9, 2021 at 5:34 pm

    Hello,

    valueAtTime(time-thisComp.frameDuration*time)-1;

    // it doesn't return the value of the previous frame


    // Try:

    valueAtTime(framesToTime(timeToFrames(time)-1));

  • Joss Gitlin

    February 9, 2021 at 6:38 pm

    Oops. I had somehow left that extra “*time” in there!

    Is it not possible to get the value calculated by the expression at the previous frame? That’s exactly what I need to do…

  • Dan Ebberts

    February 9, 2021 at 6:55 pm

    That’s correct, but there are usually work-arounds. The most drastic one (which may be what you need) is for your expression to loop through all previous frames to re-calculate everything the expression has done on previous frames. The obvious downside is that the expression will eventually bog down because it has to do more and more calculations at each frame.

  • Joss Gitlin

    February 10, 2021 at 2:40 am

    Gotcha. I saw you use a similar approach on your website for an audio threshold expression. I’ll look into that. I really only need to look back on the previous 3 frames

  • Dan Ebberts

    February 10, 2021 at 6:01 am

    Well that’s a lot easier, and very do-able. Come back if you get stuck.

  • Joss Gitlin

    February 13, 2021 at 4:57 am

    Well Dan, I’m ashamed to admit it, but I’m stuck.

    x = thisComp.layer(“A_BASS”).effect(“Both Channels”)(“Slider”);
    threshold = 50.0;

    below = false;
    frame = Math.round(time / thisComp.frameDuration);
    oldFrame = Math.round(time / thisComp.frameDuration) – 3;

    d = 3;
    n = 0;
    while (frame > oldFrame){
    t = frame * thisComp.frameDuration;
    if (below){
    if (x.valueAtTime(t) >= threshold){
    n=100+x;
    below = false;
    }
    else d–;
    }
    else if (x.valueAtTime(t) < threshold && d < 1){
    below = true;
    n=102;
    d = 3;
    }
    frame–
    }

    n

    I need the ‘else if’ statement to only trigger when the x value is below the threshold for 3 consecutive frames, which is what I’m attempting to use the d variable for.

  • Joss Gitlin

    February 13, 2021 at 5:46 am

    I finally got it!

    This expression checks the past 3 frames to see if they all fall below the threshold, and if so, executes a command.

    x = thisComp.layer(“A_BASS”).effect(“Both Channels”)(“Slider”);
    threshold = 50.0;

    wentBelow = false;
    isBelow = false;
    frame = Math.round(time / thisComp.frameDuration);
    oldFrame = Math.round(time / thisComp.frameDuration) – 3;

    d = 3;
    n = 0;
    while (frame > oldFrame){
    t = frame * thisComp.frameDuration;
    if (x.valueAtTime(t) >= threshold){
    n=100+x;
    wentBelow = false;
    break;
    }
    else wentBelow = true;
    if (wentBelow){
    d–;
    if (d < 1) {
    n = 102;
    break;
    }
    }
    else if (x.valueAtTime(t) < threshold){
    wentBelow = true;
    }
    frame–
    }

    n

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