Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions How to keep a value in a if/else condition

  • How to keep a value in a if/else condition

    Posted by Olivier Turcotte on April 18, 2012 at 12:45 pm

    Hi,

    I’m a newbie in after effect and I’m playing with expressions. I want a value to be updates if the condition is meet, but to keep the value if not.
    Thanks

    if (transform.position[2] > -1) {
    -keep the value. (do nothing)
    } else {
    text.animator("Animator 1").selector("Range Selector 1").offset
    };

    Dan Ebberts replied 14 years, 4 months ago 3 Members · 6 Replies
  • 6 Replies
  • Declan Smith

    April 18, 2012 at 1:21 pm

    Just put value there as below

    if (transform.position[2] > -1) {
    value
    } else {
    text.animator("Animator 1").selector("Range Selector 1").offset
    };

    Declan Smith
    https://www.madpanic.tv
    After Effects CS5.5/ FCS3 / Canon 7D / Canon XL2 / Reason / Cubase

    “it’s either binary or it’s not”

  • Olivier Turcotte

    April 18, 2012 at 1:34 pm

    Thanks, I ve try and it goes back to zero, and I want it to keep the last known values. so… if its true continue your path else keep your value at this time.

  • Olivier Turcotte

    April 18, 2012 at 2:09 pm

    Thanks, Ove try this and when the condition is not meet, it return to zero. I want it to keep the last know value.

  • Dan Ebberts

    April 18, 2012 at 5:28 pm

    This is one of those things that seems like it should be simple, but really isn’t. It’s because an expression has no access to values it calculated in the past. What you need is a threshold detector–a piece of code that goes back in time, frame-by-frame, looking for the most recent frame where the layer’s z position went from being less than -1 to being greater than -1. Try this:


    threshold = -1;
    trig = false;
    for (f = timeToFrames(time); f >= timeToFrames(inPoint); f--){
    tCur = framesToTime(f);
    v = transform.position.valueAtTime(tCur)[2];
    if (trig && (v < threshold)) break;
    if (v >= threshold) trig = true;
    }
    t = (trig) ? framesToTime(f+1) : time;
    valueAtTime(t)

    Dan

  • Olivier Turcotte

    April 19, 2012 at 1:30 pm

    Thanks for the help, it doesnt work. It go back to zero. I want the offset value of my text layer to stodd still when the Z position is close to zero. Im sending my project file if you want to have a look at it.

    4006_example.aep.zip

  • Dan Ebberts

    April 19, 2012 at 5:30 pm

    Ah, OK. Change the last line to this:

    text.animator(“Animator 1”).selector(“Range Selector 1”).offset.valueAtTime(t)

    Dan

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