4 Replies Latest reply on Feb 26, 2017 9:15 AM by Rick Gerard

# Count up, skipping some numbers

Hey, I'm still an absolute beginner regarding Ae.
I am trying to create an Count up from -2 to roughly 160. The thing is, I need to skip some numbers. How do I do that?

Thanks a lot!

• ###### 1. Re: Count up, skipping some numbers

The easiest way would be to use an expression on the source text property of a text layer. The math involved depends on how fast you want the counter to go up and which numbers you want to skip. For example if you used this expression you could convert time into frames, then divide the frames by the number of frames you wanted the number to stay the same, then multiply the result by 2. This would give you a count  that was only even numbers -2, 0, 2, 4, 6,  8 and so on. You could then add an if statement to stop the count at 160.

Another option would be to apply Math.Round to the value of a slider and then animate the value of the slider. This will give you whole numbers. You could divide these whole numbers by 2 to give you even numbers or 4 or 3. Then to skip groups of numbers you could add some additional keyframes.

Please give us a detailed explanation of exactly what you are trying to do and we can probably quickly point you to an efficient solution.

• ###### 2. Re: Count up, skipping some numbers

Alright, the thing is I want to skip more or less random numbers. I want to skip 1, 2, 154 and some more.

• ###### 3. Re: Count up, skipping some numbers

How random is random? Without more info nobody can tell you much. There's a million ways to do this. Code is fluid and many different methods can produce similar results. That said, it seems to me you are overcomplicating this. Counting from -2 to 160 can easily be done using the Numbers effect and skipping any numbers would just be some more keyframes. Perhaps you might care to actually read the help and watch some basics tutorials....

Mylenium

• ###### 4. Re: Count up, skipping some numbers

If I had a bit more sleep I'd be able to make this more precise. Here is how I would approach the problem if I needed to do this often or make a bunch of adjustments in the timing. If it was a one time only problem I would probably just use the numbers effect or add some keyframes to source text.

I would add an empty text layer and then add an expression slider to that text layer. The goal here is to set the starting and ending values for your count using keyframes for the slider. To that you would want to add a random value that always increases. Because expressions do not remember what values were in the previous frame you'll have to add a Java accumulator to go back to the first frame of the layer and then add the accumulated random numbers based on time. When you get to your maximum number you need an if statement that stops the count. That's a bit complicated so let me just give you a step by step:

1. Create a new empty text layer then select the layer in the timeline using the selection tool (v)
2. With the layer selected choose Effect>Expression Controls>Slider Controls to add a slider to the text layer
3. Press the u key twice to reveal the source text property and the expression control
4. Hold down Alt/Option and click on the Source Text stopwatch to add an expression
5. Copy and paste this expression to Source Text
j = 0;     //initialize loop counter
accum = 0; //initialize random accumulator
seedRandom(index,true);

while (j < time){
accum += random(5);
j += thisComp.frameDuration;
}

n = Math.round(effect("Slider Control")("Slider") + accum/10);
if (n < 160) {n} else 160
6. Set a keyframe for the Slider of -2 to start the count
7. Move down the timeline to about where you want the count to stop and set the ending value (160)
8. Set the CTI to the point where you want the counter to reach 160 and then drag the last keyframe in the slider back and forth to make the numbers stop counting when you want them to stop

If you need different numbers you will have to match the last keyframe value of the Slider to the numbers in the if statement. If you want a bigger change in the random numbers you'll need to edit the (5) in the random method to a different number. As it exists now it add a random number between 0 and 5 to the value of the slider.

I hope this helps. As inelegant as it is it will give you a randomly increasing count up that you can time to your needs. Here's an animation preset that will do the job. Dropbox - Random Count Up with slider.ffx

Just save it to your Custom presets folder and then apply it to an empty text layer.