Skip to main content
Participating Frequently
April 27, 2023
解決済み

Decreasing Digital timer error

  • April 27, 2023
  • 返信数 1.
  • 425 ビュー

Hi!

 

I've been trying to get a decreasing digital timer using expression. 

 

This is what I have so far:

slider = thisComp.layer("TIME").effect("Slider Control")("Slider")

sec = slider%60;

min = Math.floor(slider/60)%60;

 

function addZero(n) {

if (n < 10) return "0" + n else return n;

}

addZero(min) + ":" + addZero(sec)

 

In order te have it decrease I have linked it to a startpoint slider:

Math.floor(thisComp.layer("CONTROL").effect("TIME")("Slider") - time*1)

 

This way I can send it als a mogrt. and I dont have to worry about it anymore.

This all works fine until it reaches a value below zero, after that is starts to go negative in the decimals. 

For example: 0-1:0-3.

 

Are there any solutions to make it stop at 00:00?

このトピックへの返信は締め切られました。
解決に役立った回答 Dan Ebberts

I'm not sure where the startpoint slider fits in, but you should be able to just change your sec and min definitions, like this:

sec = Math.max(slider%60,0);
min = Math.max(Math.floor(slider/60)%60,0);

Also, if you want your addZero function to work with the JavaScript expression engine, you need to update it:

function addZero(n) {
  return (n < 10 ? "0" : "") + n;
}

 

返信数 1

Dan Ebberts
Community Expert
Dan EbbertsCommunity Expert解決!
Community Expert
April 27, 2023

I'm not sure where the startpoint slider fits in, but you should be able to just change your sec and min definitions, like this:

sec = Math.max(slider%60,0);
min = Math.max(Math.floor(slider/60)%60,0);

Also, if you want your addZero function to work with the JavaScript expression engine, you need to update it:

function addZero(n) {
  return (n < 10 ? "0" : "") + n;
}

 

Participating Frequently
April 27, 2023

That did the trick! Thank you.