Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Increase variable each frame, check if it’s too big and reset it, then keep increasing

  • Increase variable each frame, check if it’s too big and reset it, then keep increasing

    Posted by Jacob Mcgarry on February 27, 2015 at 6:53 pm

    Hey all,
    So I’m pretty new to AE, and very new to expressions, but I do have some experience with entry level coding. I have a layer that is tiled, and I want it to scroll downward with increasing speed. Accomplishing that is pretty easy, I just used this expression:

    temp = transform.position[1];
    spd = effect(“Slider Control”)(“Slider”);
    temp = (time*spd);
    [960, temp]

    Then I keyframed the slider to increase over time. However, the problem arises when I run out of tiles. I could just increase the number of tiles to something enormous, but because I’m speeding up more and more over time, I don’t think that’s the best solution. I decided to make an if statement that would reset the position to 0 once I reached the end of my tile.
    I tried this:

    temp = transform.position[1];
    spd = effect(“Slider Control”)(“Slider”);
    temp = (time*spd);
    if (temp > 12960) temp = 0;
    [960, temp]

    But unfortunately when it hits the if statement, it resets the position then stops increasing temp each frame. SO what I need is a loop that will increase temp, the reset the position if it’s too big. My last attempt was this:

    temp = transform.position[1];
    spd = effect(“Slider Control”)(“Slider”);
    for (i=0; i 12960) temp = 0;
    }
    [960, temp]

    But that does the exact same thing as the second one AFAIK. Thanks, any help would be appreciated.

    temp = transform.position[1];
    spd = effect("Slider Control")("Slider");
    for (i=0; i 12960) temp = 0;
    }
    [960, temp]

    Jacob Mcgarry replied 11 years, 6 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    February 27, 2015 at 7:18 pm

    With expressions, variables don’t survive from one frame to the next. You could try this:

    temp = transform.position[1];
    spd = effect(“Slider Control”)(“Slider”);
    temp = (time*spd)%12960;

    although, if you’re keyframing your speed slider, you’re probably going to run into other issues:

    https://www.motionscript.com/articles/speed-control.html

    Dan

  • Jacob Mcgarry

    February 27, 2015 at 8:03 pm

    You were totally right on both accounts, modulus totally works in this case, and I am having other troubles with the keyframing. Thanks!

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