Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Change Value on Previous Keyframe in Index, not Nearest

  • Change Value on Previous Keyframe in Index, not Nearest

    Posted by Jonathan Moxness on July 31, 2020 at 7:04 pm

    I have an expression on a Null slider (“Magazine control”) that I want to add 25 to the value of every time I add a keyframe to another slider on the same Null (“Magazine Reload”). Currently I have it mostly working except it’s changing when it’s closer to the next keyframe than it is to the previous, and I want it to change only when it hits the next keyframe, not when it’s closer, so I need to reference the previous keyframe instead, and I’m not sure how to do that.

    Here’s my expression currently (applied to the “Magazine control” slider effect):

    reload = effect(“Magazine Reload”)(“Slider”).nearestKey(time).index;
    Math.round(value)+(25*reload);

    I found a couple other forum posts referencing previous keyframes in expressions, but I couldn’t figure out how to translate them to my problem.

    reload = effect("Magazine Reload")("Slider").nearestKey(time).index;
    Math.round(value)+(25*reload);

    Jonathan Moxness replied 5 years, 12 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    July 31, 2020 at 7:21 pm

    I haven’t tested it, but it should be like this:

    reload = effect(“Magazine Reload”)(“Slider”).nearestKey(time).index;
    if (time < effect(“Magazine Reload”)(“Slider”).key(reload).time) reload–;
    Math.round(value)+(25*reload);

    Dan

  • Jonathan Moxness

    July 31, 2020 at 7:56 pm

    Thank you so much Dan! Works perfect!

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