Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › Making Current Speed and Maximum Speed

  • Making Current Speed and Maximum Speed

    Posted by Amin Persia on October 5, 2012 at 9:58 pm

    Hello,

    I’m very new to AE Expressions. I have two text layers one is currentSpeed and second one is maxSpeed. currentSpeed is always changing rangin from 0 to 135. I want the maxSpeed to check currentSpeed. If currentSpeed is higher, then change to higher value. Else, stay at it’s current value.

    I tested a lot but it doesn’t work.

    Can someone help me with this?

    Tnx.

    max = text.sourceText
    crSpeed = thisComp.layer("speed").text.sourceText
    if (crSpeed > max) {max = crSpeed}

    Darby Edelen replied 13 years, 11 months ago 3 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    October 5, 2012 at 10:40 pm

    >I’m very new to AE Expressions

    That makes me wonder if you know that expressions have no memory (expression results can not be passed from one frame to the next). I’m guessing that you want one text layer to present the maximum value of the other, up to the current time, is that correct? If so, at each frame, your expression will have to examine the value at all previous frames to find the maximum. Since it will be doing more and more work at each successive frame, things can slow down if your comp is long. Here’s an expression that does what I’ve described:


    max = 0;
    fCur = timeToFrames(time);
    fStart = timeToFrames(inPoint);
    for (f = fStart; f <= fCur; f++){
    t = framesToTime(f);
    temp = parseFloat(thisComp.layer("speed").text.sourceText.valueAtTime(t));
    max = Math.max(max,temp);
    }
    max

    Dan

  • Amin Persia

    October 5, 2012 at 10:52 pm

    Tnx. Yea I didn’t know expressions don’t have memory. And yes the comp got so much slower. The max time it can handle is about 3mins and the scene is not that complex at all.

  • Darby Edelen

    October 5, 2012 at 10:55 pm

    After Effects does not have persistent memory for expressions. The entire expression is evaluated on each frame without regard for previous or next frames.

    You can do this but it requires that you not only check the current frame but every previous frame as well. Also I believe you need to force the string objects into numbers:


    t = timeToFrames(time);
    max = 0;
    for(x = 0; x <= t; x++){
    crSpeed = thisComp.layer("speed").text.sourceText.valueAtTime(framesToTime(x)) * 1;
    if (crSpeed > max) max = crSpeed;
    }
    max;

    Darby Edelen

  • Darby Edelen

    October 5, 2012 at 10:55 pm

    Dan’s solution is, of course, more elegant 🙂

    Darby Edelen

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