Skip to main content
Known Participant
October 21, 2018
Answered

After Effects script error...bug?

  • October 21, 2018
  • 1 reply
  • 6409 views

Hi,
I'm trying to create a countdown-timer in Adobe After Effects using this script attaching it to the source text property of a text layer:


- - - - - - - - - - - - - -

rate = -1;

clockStart = 300;

function padZero(n){

if (n < 10) return "0" + n else return "" + n

}

clockTime = Math.max(clockStart + rate*(time - inPoint),0);

t = Math.floor(clockTime);

min = Math.floor((t%3600)/60);

sec = Math.floor(t%60);

min + ":" + padZero(sec)

- - - - - - -

However, I can't get it to work (my text just disappears) and there is an error message:
This project contains an expression error: Error 1 of 1

Some sites suggest you can click the symbols on the right of the orange warning banner with this message but it just flashes for half a second before it goes away. Only way I can initiate it is by changing a value in the script and click outside of the script area but as soon as I release the mouse the error message goes away.

Could this be a bug? Not knowing whats wrong with the script and not even able to learn more about it using the error-banner gives me little luck in finishing this countdown-timer with the accompanying script (or using any script for that matter if it's not imediately correct).


Any help greatly appriciated.

I'm in Adobe AfterEffects CC 2019

This topic has been closed for replies.
Correct answer Dan Ebberts

The extra 0 before the seconds works for me, but from your description it sounds like you also want if before the minutes. If so, change the last line to this:

padZero(min) + ":" + padZero(sec)

>I still wonder why the error-banner disappears..

I think it's a bug (I filed a bug report on it). The error itself occurs because the new JavaScript engine doesn't accept the if/else syntax in the padZero function like the previous engine would. Just adding a semicolon like this would fix it as well:

if (n < 10) return "0" + n; else return "" + n

Dan

1 reply

Dan Ebberts
Community Expert
Community Expert
October 21, 2018

This should fix it:

rate = -1;

clockStart = 300;

function padZero(n){

  return (n < 10 ? "0" : "") + n;

}

clockTime = Math.max(clockStart + rate*(time - inPoint),0);

t = Math.floor(clockTime);

min = Math.floor((t%3600)/60);

sec = Math.floor(t%60);

min + ":" + padZero(sec)

Dan

flyermclAuthor
Known Participant
October 21, 2018

Thanks Dan!

That got it working. Seems like it was the ? that made it work. However I can't seem to get an extra 0 before the seconds...

So its

10:00

  9:59

  9:58

were it preferably should say

10:00

09:59

09:58

etc...

Also, I still wonder why the error-banner disappears.. o_o

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
October 21, 2018

The extra 0 before the seconds works for me, but from your description it sounds like you also want if before the minutes. If so, change the last line to this:

padZero(min) + ":" + padZero(sec)

>I still wonder why the error-banner disappears..

I think it's a bug (I filed a bug report on it). The error itself occurs because the new JavaScript engine doesn't accept the if/else syntax in the padZero function like the previous engine would. Just adding a semicolon like this would fix it as well:

if (n < 10) return "0" + n; else return "" + n

Dan