Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Different If/Else statments

  • Different If/Else statments

    Posted by Diego Fonseca on October 11, 2009 at 6:53 pm

    Hi there, this must be an AEExpression 101 but I’ve just started messing around with expressions.

    I need to execute some different movements on a 3d layer with a simple wiggle, stop the movement for a while and then begin it again. My question is, How can I declare and If/else statement and then when it is done the code executes the next if/else statement?. I came up with this basic solution but it doesn’t work. Tha code is within the Layer’s position.

    But what I’m reallyx2 interested in knowing how to execute and array of If/Else statements one at a time, I mean one after another in a consecutive order. Like respecting a simple coma or something like that 🙂 (I know is not that simple but you know what I mean.

    Thanxs for any hint on this one. Have a nice day.

    shakeTime = 2;
    stopTime = 4;

    if((time<shakeTime) && (time>stopTime)){
    wiggle(8,10);
    }else{value,value,value;
    }

    // and then after this do something else like change the opasity with another If/else statement.

    Paul Hennell replied 16 years, 7 months ago 4 Members · 3 Replies
  • 3 Replies
  • Xinlai Ni

    October 11, 2009 at 9:56 pm

    The naive way to do is using for loop to determine which interval you are in, and decide accordingly:
    var interval = [
    shake0,
    stop0,
    shake1,
    stop1,

    shakeN,
    stopN
    ];

    for (i = 0; i <= 2*N; ++i) { if (time < interval[i]) { break; } } if (i == 0) { // return stop position my_stop_position } else { // Now time is between interval[i - 1] and interval[i] if (i % 2 == 1) { // time is between shake[i] and stop[i], wiggle it. wiggle(...) } else { // stop it my_stop_position } } Xinlai Ni

  • Dan Ebberts

    October 11, 2009 at 10:39 pm

    If each segment is the same duration, you could use a JavaScript switch() statement like this:

    segDur = 2; // each segment is 2 seconds
    curSeg = Math.floor(time/segDur);
    switch(segDur){
    case 0:
    // your fist block of code goes here
    break;
    case 1;
    // your second block of code goes here
    break;
    case 2:
    // your third block of code goes here, etc.
    break;
    default:
    // code to execute if segDur doesn’t match any of your cases
    break;
    }

    Dan

  • Paul Hennell

    October 13, 2009 at 4:05 pm

    I used a quick work around when I wanted to do something like this before; Added a slider control to the layer, then used “If Slider = 1”, “if Slider = 2” etc for the code blocks. Then just animated the slider number manually to call each block when I wanted it. Provided you don’t want to keep changing the timings lots, it works well and is easy to control.

    (I also frequently use a check-box to control wiggle on/off, or a slider to easily adjust a wiggle value from on to off. Expressions joined with Manual controls really work very well together 😉 )


    Only in after effects do children get to pick and whip their parents.
    https://hennell-online.co.uk

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