Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions If / Else with No Else?

  • If / Else with No Else?

    Posted by Brent Taylor on January 16, 2015 at 12:34 am

    I’m just barely learning and this is probably a bit basic but I’d appreciate any help.

    I am trying to put a couple conditions on the same expression. It works great except for one problem. My code works like this:

    if
    (various conditions are met)
    12

    else
    if
    (other conditions)
    1

    else

    5

    You’ll notice the “else 5” at the bottom… that’s the problem. I DON’T actually want a final “else.” If none of the conditions are met, I’d like the value to just stay wherever it was last. However, without a final “else… something” it will insist on reverting to zero when nothing is met.

    How can I get it to just hold the last value?

    I feel like it must be possible, because if I have only the first part:

    if
    (various conditions are met)
    12

    It works the way I’d want. But once I add the second (even if I forgo the else syntax) it doesn’t allow that.

    I put the actual code below if you need more detail… it’s basically a simple collision detector. But I don’t want the value to revert when the collision is over. I want it to stay until the pointer runs into a new object.

    So basically I’d just like the else to do nothing at all.

    t=100

    if
    (thisComp.layer("pointer thing").transform.xPosition <= thisComp.layer("A12").transform.xPosition + t && thisComp.layer("pointer thing").transform.xPosition >= thisComp.layer("A12").transform.xPosition - t && thisComp.layer("pointer thing").transform.yPosition <= thisComp.layer("A12").transform.yPosition + t && thisComp.layer("pointer thing").transform.yPosition >= thisComp.layer("A12").transform.yPosition - t)
    12

    else
    if
    (thisComp.layer("pointer thing").transform.xPosition <= thisComp.layer("A11").transform.xPosition + t && thisComp.layer("pointer thing").transform.xPosition >= thisComp.layer("A11").transform.xPosition - t && thisComp.layer("pointer thing").transform.yPosition <= thisComp.layer("A11").transform.yPosition + t && thisComp.layer("pointer thing").transform.yPosition >= thisComp.layer("A11").transform.yPosition - t)
    11
    else
    5

    Dan Ebberts replied 11 years, 7 months ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    January 16, 2015 at 12:54 am

    It sounds like you want the expression to remember a previous result, which it can’t do. Expressions only have access to the host property’s pre-expression value.

    If I understand what you’re trying to do, your expression will have to loop through all the frames prior to the current time to figure out what the current value should be.

    Dan

  • Brent Taylor

    January 16, 2015 at 1:41 am

    Hmm. Well, remembering a previous result would work. I know it can’t do that, though. I haven’t learned about how to loop through how you said yet… hmm.

    On the other hand, I don’t really need it to remember anything… I just don’t want it to send a value to another layer unless it’s one of the ones a collision would input… is there any way to do that?

    The idea here is to use the collision detection I’ve made as sort of a realtime controller for another layer which is running Time Remapping. Running the Motion Sketch, I can run the pointer across various areas, which other layers can then use for input to receive values.

    I already have this working great. It’s just that the expression wants to also send a value whenever a collision ISN’T happening. That’s ok for some situations, but I want also want the option to be able to go between the various values without having to revert to a “default” in between. This way you can go from any value to any other value.

    Perhaps there is some way to get the layer on the receiving end to ignore that default value? That’s what I’m experimenting with right now, but I can’t seem to get it to work. I tried this making a second slider whose input was parented to the first, conditional on it NOT being a particular value (the last “else” value from the other expression…)

    if
    effect(“Slider Control 2”)(1)!=5

    {effect(“Slider Control 2”)(1)}

    But that didn’t work, either…

  • Dan Ebberts

    January 16, 2015 at 1:47 am

    > I just don’t want it to send a value to another layer unless it’s one of the ones a collision would input… is there any way to do that?

    An expression has to generate a result.

    Dan

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