Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Multiple conditions in if/else statement.

  • Multiple conditions in if/else statement.

    Posted by Eric Sanderson on June 17, 2009 at 6:35 pm

    This is something ive been wondering for a while but havent ran into an urgent situation to use it til now.

    the SET UP:

    i have basically a glorified slide show going on..with the typical effect as taking a picture, cutting out pieces and zooming in and out creating depth with paralax and lens blur. So i have a LOT of these comps set up and what ive done is made a null called “controller” that i can just duplicate into each comp and parent all of the layers to…heres whats on the Nulls position…

    rev=effect(“reverse”)(“Checkbox”);

    z=time*effect(“Speed”)(“Slider”);
    zR=time*-effect(“Speed”)(“Slider”);

    pIn=value+[0,0,z];
    pOut=value+[0,0,zR];

    if(rev==true){pIn
    }else{
    pOut
    }

    So i have a slider controlling the speed of the push in, and a checkbox if i want to reverse it and pull out. My question can pertain to this setup but i found a work around that works cuz i will always be either pushing in or pulling out…but heres what i cant work around.

    the QUESTION:

    id like to also just be able to make a checkbox on the null named rotate CW and one named rotate CCW, and to be able to check one or the other to make the scene rotate as its pushing in, my problem is i know i can set it up like previously shown BUT i want to be able to just leave the rotation off by leaving the boxes unchecked if i want to. Which is why i need to know how to “correctly” say.

    rCCW=effect(“Rotate CCW”)(“Checkbox”);
    rCW=effect(“Rotate CW”)(“Checkbox”);

    zRotCCW=value-time/2;
    zRotCW=value-time*2;

    if(

    if(rCCW==true)zRotCCW
    and if (rCW==true)zRotCW
    and if (rCCW&&rCW==false)0,

    ….So how do i say all of that in one if/else statement?

    sorry if this took forever to explain, i like to not just explain the specific script question but also the application for it incase someone has a better way to the solution all together. thank you.

    Eric Sanderson replied 16 years, 10 months ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    June 17, 2009 at 8:00 pm

    Try this:

    rCCW=effect(“Rotate CCW”)(“Checkbox”).value;
    rCW=effect(“Rotate CW”)(“Checkbox”).value;

    zRotCCW=value-time/2;
    zRotCW=value+time/2;

    if(rCCW){
    zRotCCW
    }else if (rCW){
    zRotCW
    }else{
    value
    }

    Dan

  • Eric Sanderson

    June 17, 2009 at 8:12 pm

    So does stating the variable in the “( )” with no condition just default to saying if the value is true? and to enable that to work is what .value was at the end of the variable was for? Guess im trying to read how that code would sound in a sentence, thats how i usually learn best.

    And to answer my question if at anytime i need to keep adding conditions i do that by “}else if(){“.

    what ive always wondered is sometime i see codes, including many of yours that say “if(” and then go on with multiple lines of codes, a lot of them usually defining variables within the statement…just always wondered about that. Thanks for the help!

  • Dan Ebberts

    June 17, 2009 at 8:25 pm

    You need the .value to retrieve the actual value of a checkbox. It seems a little incosistent because you don’t need to do that with sliders.

    The if statement evaluates whatever’s in the () and if it evaluates to anything other than 0 (false) it will execute the next statement (or group of statements enclosed in {}).

    Dan

  • Eric Sanderson

    June 17, 2009 at 8:39 pm

    Thats strange as ive never used .value with checkboxes and i seem to get the result im looking for.

    I see so as default it would pretty much be the equivalent of saying”if(value>0){execute”…and thats why in many cases you dont need the “else”, because it defaults to 0 (or false) anyways.

  • Eric Sanderson

    June 18, 2009 at 4:20 pm

    ok i think i figured it out lol. the prob was i was “saving animation preset” from the effects window and not the animation tab, so i was saving just an effect preset. got it.

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