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

Decreasing Digital timer error

Community Beginner ,
Apr 27, 2023 Apr 27, 2023

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?

TOPICS
Expressions , Scripting
357
Translate
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

Community Expert , Apr 27, 2023 Apr 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;
}

 

Translate
Community Expert ,
Apr 27, 2023 Apr 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;
}

 

Translate
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 ,
Apr 27, 2023 Apr 27, 2023
LATEST

That did the trick! Thank you.

Translate
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