Skip to main content
Participant
November 7, 2022
Answered

Increase value by 1 only at every ODD keyframe?

  • November 7, 2022
  • 1 reply
  • 208 views

Hello! I have this expression that makes the value increase by 1 at every keyframe of "s" property.

s = effect("switch")("Checkbox");
ld = comp("lineDistribution").layer("ctrl");

n = s.nearestKey(time).index;
if (s.key(n).time > time) n--;
n;

 It's working perfectly. But how do I make the value increase only at ODD keyframes?

Like:

at key(1), value is 1
at key(2), value is 1
at key(3), value is 2
at key(4), value is 2

 

This topic has been closed for replies.
Correct answer Dan Ebberts

Try changing the last line to this:

Math.floor((n+1)/2);

1 reply

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
November 8, 2022

Try changing the last line to this:

Math.floor((n+1)/2);
hxney2021Author
Participant
November 8, 2022

Thank you! It worked