• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Timer decimals don't show all numbers

Community Beginner ,
Nov 12, 2022 Nov 12, 2022

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?

TOPICS
Expressions

Views

141

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Nov 12, 2022 Nov 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 

Votes

Translate

Translate
LEGEND ,
Nov 12, 2022 Nov 12, 2022

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 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 12, 2022 Nov 12, 2022

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):

Captura de pantalla 2022-11-12 163234.pngCaptura de pantalla 2022-11-12 163254.pngCaptura de pantalla 2022-11-12 163342.png

I think the expression doesn't have any rounding functions. But i'm pretty sure it has something to do with the frame rate.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 12, 2022 Nov 12, 2022

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 12, 2022 Nov 12, 2022

Copy link to clipboard

Copied

LATEST

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 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines