Copy link to clipboard
Copied
I have a text layer with an expression that makes a timer with 2 decimals start and stop counting with at every Checkbox Control keyframe. The expression works perfectly, but for some reason, the 2nd decimal only shows some numbers. There's nothing wrong with the expression, I think it's because the frame rate is 30?
Anyway, does anybody know if there's some way to make the decimal show every number?
As Rick explained already there's nothing wrong with the math. If you want more variation you could of course add some additional function like a cosine based on two or three second intervals so the numbers alternate ever so slightly. Likewise, you could posterize the time or use a different framerates inside the expression. Plenty of ways to make this look more interesting.
Mylenium
Copy link to clipboard
Copied
Without seeing your code and screenshots of the result nobody can tell you anything. This could be anything from rounding functions in the code to the font not producing the correct numeral character due to glyph substitution. You really have to provide much more info.
Mylenium
Copy link to clipboard
Copied
Okay, here's my expression. It makes the timer start counting at every "switch" Checkbox ODD keyframe and stop at every EVEN keyframe.
s = effect("switch")("Checkbox");
n = s.nearestKey(time).index;
if (s.key(n).time > time) n--;
t = 0;
if (n%2 == 1) t += time - s.key(n).time;
for (i = 2; i <= n; i++){
if (i%2 != 1) t+= s.key(i).time - s.key(i-1).time;
}
t
The 2nd decimal of the timer/stopwatch only shows 0, 3 and 7 (instead of showing all numbers: 0,1,2,3,4,5,6,7,8,9):
I think the expression doesn't have any rounding functions. But i'm pretty sure it has something to do with the frame rate.
Copy link to clipboard
Copied
You are calculating time, and keyframes always start at the start of a frame. 1 second / 30 = .3333 so the time is going to be rounded to the nearest 30% which is .00, .03, .07. for 30 fps.
You should also modify your expression like this:
s = effect("switch")("Checkbox");
n = s.nearestKey(time).index;
if (s.key(n).time > time) n--;
t = 0;
if (n%2 == 1) t += time - s.key(n).time;
for (i = 2; i <= n; i++){
if (i%2 != 1) t+= s.key(i).time - s.key(i-1).time;
}
t.toFixed(2)
You
Copy link to clipboard
Copied
As Rick explained already there's nothing wrong with the math. If you want more variation you could of course add some additional function like a cosine based on two or three second intervals so the numbers alternate ever so slightly. Likewise, you could posterize the time or use a different framerates inside the expression. Plenty of ways to make this look more interesting.
Mylenium