Copy link to clipboard
Copied
Hi all!
I'm currently working on a timer in AE — it will be used for SAT tests, so I have to make sure that it keeps perfect time. Here's the code I've used to create it:
slider=effect("Slider Control")("Slider");
sec=slider%60;
min=Math.floor(slider/60);
function addZero(X){
if(X<10)return"0"+X else return X;
}
addZero(min)+":"+addZero(sec)
While this function does keep perfect time, it displays all the decimals in between each whole second (00:00.96666666...). Is there a code I can insert that limits the displayed decimals to just the minutes and seconds, and doesn't round up the numbers? (I've found using slider = Math.round(effect("Slider Control")("Slider")); rounds the time up and displays the seconds before they should. EX: 00:02 shows up at 00:01:15 instead of 00:02:00)
Any and all help is greatly appreciated.
Thanks, have a great day!
— Joshua L
OK:
slider=effect("Slider Control")("Slider");
sec=Math.floor(slider%60);
min=Math.floor(slider/60);
function addZero(X){
if(X<10){
return"0"+X
}else{
return X
}
}
addZero(min)+":"+addZero(sec)
Copy link to clipboard
Copied
Would replacing your second line with this help:
sec=Math.floor(slider%60);
But - wouldn't it be easier just to use the built in expression 'time' function to do this job? Or do you need the flexibility of this keyframeable approach?
Copy link to clipboard
Copied
That did the trick!! Thank you so much Mike!
I've actually never used that function before. Admittedly, I'm a bit new to After Effects. How does that work?
Or would you happen to have a link to a tutorial that explains how that works?
Thanks again, have a great day!
— Joshua L
Copy link to clipboard
Copied
Just type : time
into the expression field of a text source property. Then hit the spacebar. It will output the 'current time' in seconds : )
PS: If you can hit 'correct answer' on my first reply that will mark this thread as answered.
Copy link to clipboard
Copied
How that sounds really helpful actually. Thanks for taking the time to explain!
Will do!
Copy link to clipboard
Copied
That Expression will not work with AE's Javascript engine - it will throw up an error. Where did you get this script?
Copy link to clipboard
Copied
OK:
slider=effect("Slider Control")("Slider");
sec=Math.floor(slider%60);
min=Math.floor(slider/60);
function addZero(X){
if(X<10){
return"0"+X
}else{
return X
}
}
addZero(min)+":"+addZero(sec)
Copy link to clipboard
Copied
I strongly approve your OK. 🙂
Copy link to clipboard
Copied
: )