Copy link to clipboard
Copied
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?
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;
}
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
That did the trick! Thank you.