In this tutorial, Shae Thompson covers how to create a countdown timer in After Effects by using expressions.
Transcript
Hi friends. So today, we'll learn how to make a count-up timer using source text and a slider expression. So first, what we want to do is we want to double-click the text, and then we're going to go into effect and then expression controls and then slider control. So now we have a slider on our text. Then we want to highlight the source text next, but we only want to see the source text. So we're going to hit SS to single it out. And then what we're going to do next is we're going to hit option and then hit the little time button so we can have our expression come up.
And then this is how we're going to make our count-up timer. So we're going to delete all of this. And initially, we have to define what our slider is. So we're going to say slider equals, and we're going to take this little pick whip, and we're going to go to the slider, which should look like this. So the next thing we have to do is define our frames, our seconds, and our minutes. So we're going to define frames as sliders.
We're defining it as 30 because this project has 30 frames in a second. And then we're going to do another pair of brackets. Then we're going to go slider divided by 30. So as soon as it hits 30, it's going to put a one instead of completely restarting. Because what this does right here is when you put slider modulus 30, once it hits 30, it goes back down to zero. So any number above 30 would go back to zero and then continue to count up. So then we're going to define minutes as a slider divided by 1,800. And that's how many frames are in one minute or 60 seconds. So we click off. You'll notice that it completely reset the text. So when we move it, it'll give us a bunch of wonky numbers, and we don't want that. So let's set that back down to zero. And what we're going to do first is we're going to do math dot floor. And then, essentially, this makes it so that there are whole numbers no matter what.
So we're just going to do math dot floor again for every single one of these so that when we move it up, it goes up by one second. Sometimes they don't like to work when you go and test things out, and I can show you how to fix that. Because sometimes, when you type something like this, After Effects doesn't necessarily want to read your code. So once we get into the functions we're going to do later, I'll show you how to make it work. So what we're going to do next is we are going to make it so that there are two colons in between frames, seconds, and minutes.
So we're going to type mins plus colon plus sec plus colon plus frames. So that when we click out, we have colons right here and right here. However, when we move this slider, it will stay as one number until it gets to 10, so we're going to create a function so it doesn't do that. So we're going to return some more, and we're going to go function > add zero. Then we're going to do a curly little bracket like that. Then we're going to return. And it automatically puts a curly bracket right here at the end. Oh. Another thing so to define the add zero, we have to set N as our variable for any number so that when we type out our function, we can go if parenthesis N is less than 10. Then we do return zero ++ N else return N, so this is our function right here.
What's going to happen is After Effects usually doesn't read this as a correct function. And so when you click out, if you try and do it the way it wants you to, it'll pop up with one of these guys, saying something like this. And what happens is the word else kind of gets in the way of the function. So what you can do to solve this is you go file, go all the way down to scripts, and then update legacy expressions. So you'll do it on all compositions, and you'll just hit update, and it'll just pop up. You want to hit yes, C if else. It moves it to the top, so it works. But now that we have the function, it's gone back to its original state, so what we want to do is now we want to put our add zero right here so that every time we want like a 0, 0, 0
, it'll work this time.
So add 00. So now we can put keyframes in the slider control and create keyframes. If you want to see it in here, you can keep hitting Ss. We have a little key marker at 00.
We put another keyframe right there. And for 20 seconds, it's 600 keyframes. And you can tell it worked because now this whole green line is gone so that it does frames when you move it. And that's how you build a count-up timer. If you wanted to do a countdown timer, what you would do is you would flip your keyframes so that at the beginning, it would say 20, and at the end, it would say zero. And that's how you build a count-up and countdown timer.