Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Simple if/else statement

  • Simple if/else statement

    Posted by Jay Ingles on January 10, 2011 at 6:45 pm

    I’m having problems with if/else statements. (never done them before)

    I want to turn on/off layers based on a sliders value. I have 7 layers and want only 1 layer visible at a time. When the null slides from 1-7 i need the appropriate layer to turn on and all others off (no fades, hard cut). My expression below unfortunately doesn’t round number to an integer either.

    I’ve tried variations based around this:
    null = thisComp.layer("Null: Controller").effect("LayerID")("Slider")

    if (null = 1){
    [100];
    }else{ [0]; }

    any help is appreciated. thanks.

    Jay Ingles replied 15 years, 4 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    January 10, 2011 at 7:24 pm

    Something like this should work:

    slider = thisComp.layer(“Null: Controller”).effect(“LayerID”)(“Slider”);
    Math.round(slider) == index ? 100 : 0

    Dan

  • Jay Ingles

    January 10, 2011 at 7:37 pm

    Hmmm, when i paste this into the opacity expression nothing happens. Not clear what your expression is doing otherwise i’d try my best to fix it.

    Do i need the full 0 to 100 range or just 1 to 7?

    Thanks dan.

  • Dan Ebberts

    January 10, 2011 at 7:42 pm

    Just set the slider value to the index (the layer’s number in the layer stack in the timeline) of the layer with the expression. Any other value should make the layer invisible.

    Dan

  • Jay Ingles

    January 10, 2011 at 8:07 pm

    Thats great. Not sure what i overlooked but it works now.
    thanks

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