Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- Home
- After Effects
- Discussions
- Bug using dan eberts clock expression

- Bug using dan eberts clock expression

/t5/after-effects-discussions/bug-using-dan-eberts-clock-expression/td-p/12879724
Apr 14, 2022
Apr 14, 2022

Copy link to clipboard

Copied

I've never seen this behavior before I've got after effects updated to 22.2.1

The buggy behavior is illustrated below. It happens on whole seconds for one frame.

I've set up the clock to display in tenths of a second. Below is the clock output for every frame.

1.9, 1.9 1.9, **1.0** ,2.0 ,2.0, 2.1, 2.1, 2.1, 2.2 ... 2.9, 2.9, 2.9, **2.0**, 3.0, 3.0 etc

the error is in bold

the video ive been given is 30.303 fps

Here is the code I'm using

rate = 1.0101;

//tried making the rate 30.303/30

//ive tried 1 same behavior

clockStart = -10.06501006501007;

function padZero(n){

return (n < 10 ? "0" : "") + n;

}

clockTime = clockStart + rate*(time - inPoint)

// this is all to get the clock to start at 0 in a certain part of the clip

//clockTime = clockStart + rate*(time - inPoint); start frame was 5024 then divided by 30.303

// now i cliped it so clockstart will be at frame 5024 identified by wmh so 5024-4720 / 30.303 = 10.03201003201003

//still off by one frame so add 1/30.303

if (clockTime < 0){

sign = "-";

clockTime = -clockTime;

}else{

sign = "";

}

t = Math.floor(clockTime);

hr = Math.floor(t/3600);

min = Math.floor((t%3600)/60);

sec = Math.floor(t%60);

ms = clockTime.toFixed(1).substr(-1);

//sign + padZero(hr) + ":" + padZero(min) + ":" + padZero(sec) + "." + ms

sign + padZero(sec) + "." + ms

I wish I could post the file anyways thanks for taking a look.

TOPICS

Error or problem
,
Expressions
,
Scripting

Community guidelines

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

Explorer
,
Apr 14, 2022
Apr 14, 2022

Mylenium,

thanks for replying

Yes I have.

The problem is the clock actually appears to go backwards when using 1 decimal on whole seconds.

I don't know the functions well enough to understand. where do I find help on toFixed and substr?

Using the help pull down I don't find it in scripting help... or expression reference...

The same behavior at 30fps in a clean one piece of text composition.... with the following code.

rate = 1;

clockStart = 0;

function padZero(n){

return (n < 10 ? "0" : "") + n;

}

clo

8
Replies
8

Buzzard_Nuts
AUTHOR

Explorer
,

/t5/after-effects-discussions/bug-using-dan-eberts-clock-expression/m-p/12879790#M198190
Apr 14, 2022
Apr 14, 2022

Copy link to clipboard

Copied

The line of code that I believe is giving me problems is

**ms = clockTime.toFixed(1).substr(-1);**

1 gives me tenths of a second if I use 2 it works as expected with going "backwards"

Community guidelines

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

/t5/after-effects-discussions/bug-using-dan-eberts-clock-expression/m-p/12880093#M198196
Apr 14, 2022
Apr 14, 2022

Copy link to clipboard

Copied

Have you actually adjusted the comp framerate accordingly and/ or played around with the footage interpretation and enforced a different, more standardized framerate? Otherwise this looks perfectly normal in the sense that with your values you'll always have scenarios where two consecutive frames produce identical values do to internal rounding and quantization limits. In such a case one would rather multiply the values with a uniform value before doing the math, then divide them at the end again. I'm pretty sure there is no bug, you just reach the limits of the internal integer math.

Mylenium

Community guidelines

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

/t5/after-effects-discussions/bug-using-dan-eberts-clock-expression/m-p/12880184#M198198
Apr 14, 2022
Apr 14, 2022

Copy link to clipboard

Copied

Mylenium,

thanks for replying

Yes I have.

The problem is the clock actually appears to go backwards when using 1 decimal on whole seconds.

I don't know the functions well enough to understand. where do I find help on toFixed and substr?

Using the help pull down I don't find it in scripting help... or expression reference...

The same behavior at 30fps in a clean one piece of text composition.... with the following code.

rate = 1;

clockStart = 0;

function padZero(n){

return (n < 10 ? "0" : "") + n;

}

clockTime = clockStart + rate*(time - inPoint);

if (clockTime < 0){

sign = "-";

clockTime = -clockTime;

}else{

sign = "";

}

t = Math.floor(clockTime);

hr = Math.floor(t/3600);

min = Math.floor((t%3600)/60);

sec = Math.floor(t%60);

ms = clockTime.

rate = 1;

clockStart = 0;

function padZero(n){

return (n < 10 ? "0" : "") + n;

}

clockTime = clockStart + rate*(time - inPoint);

if (clockTime < 0){

sign = "-";

clockTime = -clockTime;

}else{

sign = "";

}

t = Math.floor(clockTime);

hr = Math.floor(t/3600);

min = Math.floor((t%3600)/60);

sec = Math.floor(t%60);

ms = clockTime.toFixed(1).substr(-1);

sign + padZero(sec) + "." + ms

(1).substr(-1);

sign + padZero(sec) + "." + ms

Community guidelines

/t5/after-effects-discussions/bug-using-dan-eberts-clock-expression/m-p/12880327#M198202
Apr 14, 2022
Apr 14, 2022

Copy link to clipboard

Copied

Try this and see if it helps:

```
rate = 1.0101;
clockStart = -10.06501006501007;
function padZero(n){
return (n < 10 ? "0" : "") + n;
}
clockTime = clockStart + rate*(time - inPoint)
if (clockTime < 0){
sign = "-";
clockTime = -clockTime;
}else{
sign = "";
}
t = padZero(clockTime.toFixed(1));
(t != 0 ? sign : "") + t
```

Community guidelines

Buzzard_Nuts
AUTHOR

Explorer
,

/t5/after-effects-discussions/bug-using-dan-eberts-clock-expression/m-p/12880365#M198203
Apr 14, 2022
Apr 14, 2022

Copy link to clipboard

Copied

Dan,

Your the best!

Redefining t works like a charm

Many thanks.

Regards,

bn

t = padZero(clockTime.toFixed(1)); (t != 0 ? sign : "") + t

Here's the whole thing for others.

rate = 1;

clockStart = 0;

function padZero(n){

return (n < 10 ? "0" : "") + n;

}

clockTime = clockStart + rate*(time - inPoint);

if (clockTime < 0){

sign = "-";

clockTime = -clockTime;

}else{

sign = "";

}

t = padZero(clockTime.toFixed(1));

(t != 0 ? sign : "") + t

hr = Math.floor(t/3600);

min = Math.floor((t%3600)/60);

sec = Math.floor(t%60);

ms = clockTime.toFixed(1).substr(-1);

sign + padZero(sec) + "." + ms

Community guidelines

/t5/after-effects-discussions/bug-using-dan-eberts-clock-expression/m-p/12880381#M198204
Apr 14, 2022
Apr 14, 2022

Copy link to clipboard

Copied

Hmmm... The code I posted for you was meant to be "the whole thing". I'm surprised it works at all with the stuff you added after

`(t != 0 ? sign : "") + t`

Community guidelines

Buzzard_Nuts
AUTHOR

Explorer
,

/t5/after-effects-discussions/bug-using-dan-eberts-clock-expression/m-p/12880408#M198205
Apr 14, 2022
Apr 14, 2022

Copy link to clipboard

Copied

Sorry

Wow! No idea!

I just tried replaced with your last post and of course it works!

I didn't mean to mess with it I just thought it got truncated.

Regards

Community guidelines

Community Expert
,

LATEST
/t5/after-effects-discussions/bug-using-dan-eberts-clock-expression/m-p/12882148#M198272
Apr 15, 2022
Apr 15, 2022

Copy link to clipboard

Copied

Good that you could already solve the issue.

By the way, if you need an easy to customize counter expression and don't want to write any code, there is one included in iExpressions:

Community guidelines

Resources

Troubleshooting FAQs

After Effects Community Recap

Getting started with After Effects

Copyright © 2023 Adobe. All rights reserved.