Skip to main content
Participant
November 12, 2022
Answered

Timer decimals don't show all numbers

  • November 12, 2022
  • 2 replies
  • 386 views

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?

This topic has been closed for replies.
Correct answer Mylenium

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 

2 replies

Mylenium
MyleniumCorrect answer
Legend
November 12, 2022

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 

Mylenium
Legend
November 12, 2022

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 

hxney2021Author
Participant
November 12, 2022

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.

Community Expert
November 12, 2022

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