Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Full-featured countdown timer

  • Full-featured countdown timer

    Posted by Jason Vore on July 25, 2008 at 8:40 pm

    Creative cows has helped me a ton in the past, so I’m contributing my full-featured countdown expression.

    Simply use it as the source text for a text layer. All you need to edit is in the first few lines.

    //Full Function Countdown Script
    //Written by Jason Vore – co*******@*****il.com

    //Attach as an expression for the source text for a Text Layer.

    intMinutesToCountdown = 3; //How many minutes you want to be counted down.
    intSecondsToCountdown = 0; //How many additional seconds you want to be counted down.

    offset = 0; //Number of seconds to hold the countdown timer at full before it starts counting down

    boolIncludeMinutes = 1; //1 to include minutes, 0 to exclude
    boolIncludeDecimalSeconds = 1; //1 to include decimal parts of seconds, 0 to exclue
    intDecimalsToInclude = 2; //Number of decimal points to include
    boolAllowNegativeTimes = 0; //1 to allow the countdown to run past 0, 0 to hold the timer at 0 seconds.
    boolIncludeLeadingZeroes = 1; //1 to include leading zeroes in front of minutes to keep text in same location

    //DO NOT EDIT ANYTHING BELOW THIS LINE!

    i = inPoint + offset; //the “time” to actually start the countdown

    intSecondsToCountdown = intMinutesToCountdown * 60+ intSecondsToCountdown; //calculates total seconds in the countdown
    fltSecondsRemaining = intSecondsToCountdown – time + i; //decimal of number of seconds remaining, uses i start the countdown at the inpoint of the clip

    if (fltSecondsRemaining > intSecondsToCountdown)
    {
    fltSecondsRemaining = intSecondsToCountdown; //If we haven’t gotten out of the offset period, reset the timer to full.
    }

    if(!boolAllowNegativeTimes)
    {
    if(fltSecondsRemaining<0) fltSecondsRemaining = 0; //If we've passed zero seconds and user has chosen not to allow negative times, reset time to 0.
    }

    intMinutesRemaining = Math.floor(fltSecondsRemaining/60); //Calculates number of minutes remaining

    decSecondsRemaining = fltSecondsRemaining - 60 * intMinutesRemaining; //reduces seconds to less than 60

    intDecimalMultiple = Math.pow(10,intDecimalsToInclude); //Multiplier for placing decimal place in the correct spot.
    decSecondsRemaining = Math.floor(decSecondsRemaining * intDecimalMultiple); // moves decimal to the right and chops remainder
    dspSecondsRemaining = decSecondsRemaining/intDecimalMultiple; //prepare the seconds for display - puts the decimal point back where it belongs

    if (!(decSecondsRemaining%intDecimalMultiple) && boolIncludeDecimalSeconds)
    {
    dspSecondsRemaining = dspSecondsRemaining + "."; //If we are at an even second and the user wants the decimal places displayed, tag the decimal point on to the string.
    }

    if(boolIncludeDecimalSeconds)
    {
    for (a=1;a<=intDecimalsToInclude;a++) { if(!(decSecondsRemaining%Math.pow(10,a))) { dspSecondsRemaining = dspSecondsRemaining+"0"; //Add appropriate trailing zeroes if we are showing decimals. } } } if(decSecondsRemaining < 1000 && boolIncludeMinutes) { dspSecondsRemaining = '0' + dspSecondsRemaining; //if we are under 10 seconds and displaying minutes, and a leading 0 to the seconds } if(boolIncludeMinutes && intMinutesToCountdown >= 10 && intMinutesRemaining<10 && boolIncludeLeadingZeroes)
    {
    dspMinutesRemaining = '0' + intMinutesRemaining;
    }
    else
    {
    dspMinutesRemaining = intMinutesRemaining;
    }

    dspMinutesRemaining + ':' + dspSecondsRemaining

    Nathaniel Schweinberg replied 16 years ago 3 Members · 3 Replies
  • 3 Replies
  • Wes Ball

    September 5, 2008 at 10:23 am

    Is there an easy-ish way to modify the code to use $ (dollars) instead of time units?

  • Nathaniel Schweinberg

    April 28, 2010 at 4:41 pm

    This is great, thanks so much!

  • Nathaniel Schweinberg

    April 28, 2010 at 5:04 pm

    One thing I noticed is that even though there is an if statement at the end saying if there is less than 10 seconds left tack on a 0 in front of the digit, it still didn’t. I adapted the script to fit for countdowns under 60 seconds =]

    //Full Function Countdown Script
    //Written by Jason Vore - codered10@hotmail.com
    //Edited by Nathaniel Schweinberg - nathaniel@ftcmedia.com

    //Attach as an expression for the source text for a Text Layer.

    intMinutesToCountdown = 0; //How many minutes you want to be counted down.
    intSecondsToCountdown = 30; //How many additional seconds you want to be counted down.

    offset = 2; //Number of seconds to hold the countdown timer at full before it starts counting down

    boolIncludeMinutes = 0; //1 to include minutes, 0 to exclude
    boolIncludeDecimalSeconds = 0; //1 to include decimal parts of seconds, 0 to exclue
    intDecimalsToInclude = 0; //Number of decimal points to include
    boolAllowNegativeTimes = 0; //1 to allow the countdown to run past 0, 0 to hold the timer at 0 seconds.
    boolIncludeLeadingZeroes = 1; //1 to include leading zeroes in front of minutes to keep text in same location

    //DO NOT EDIT ANYTHING BELOW THIS LINE!

    i = inPoint + offset; //the "time" to actually start the countdown

    intSecondsToCountdown = intMinutesToCountdown * 60+ intSecondsToCountdown; //calculates total seconds in the countdown
    fltSecondsRemaining = intSecondsToCountdown - time + i; //decimal of number of seconds remaining, uses i start the countdown at the inpoint of the clip

    if (fltSecondsRemaining > intSecondsToCountdown)
    {
    fltSecondsRemaining = intSecondsToCountdown; //If we haven't gotten out of the offset period, reset the timer to full.
    }

    if(!boolAllowNegativeTimes)
    {
    if(fltSecondsRemaining<0) fltSecondsRemaining = 0; //If we've passed zero seconds and user has chosen not to allow negative times, reset time to 0.
    }

    intMinutesRemaining = Math.floor(fltSecondsRemaining/60); //Calculates number of minutes remaining

    decSecondsRemaining = fltSecondsRemaining - 60 * intMinutesRemaining; //reduces seconds to less than 60

    intDecimalMultiple = Math.pow(10,intDecimalsToInclude); //Multiplier for placing decimal place in the correct spot.
    decSecondsRemaining = Math.floor(decSecondsRemaining * intDecimalMultiple); // moves decimal to the right and chops remainder
    dspSecondsRemaining = decSecondsRemaining/intDecimalMultiple; //prepare the seconds for display - puts the decimal point back where it belongs

    if (!(decSecondsRemaining%intDecimalMultiple) && boolIncludeDecimalSeconds)
    {
    dspSecondsRemaining = dspSecondsRemaining + "."; //If we are at an even second and the user wants the decimal places displayed, tag the decimal point on to the string.
    }

    if(boolIncludeDecimalSeconds)
    {
    for (a=1;a<=intDecimalsToInclude;a++)
    {
    if(!(decSecondsRemaining%Math.pow(10,a)))
    {
    dspSecondsRemaining = dspSecondsRemaining+"0"; //Add appropriate trailing zeroes if we are showing decimals.

    }
    }
    }

    if(decSecondsRemaining < 10) //EDIT-Removed the boolean statement requiring boolIncludeMinutes
    {
    dspSecondsRemaining = '0' + dspSecondsRemaining; //if we are under 10 seconds and displaying minutes, and a leading 0 to the seconds
    }

    if(boolIncludeMinutes && intMinutesToCountdown >= 10 && intMinutesRemaining<10 && boolIncludeLeadingZeroes)
    {
    dspMinutesRemaining = '0' + intMinutesRemaining;
    }
    else
    {
    dspMinutesRemaining = intMinutesRemaining;
    }

    ':' + dspSecondsRemaining

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy