Skip to main content
Participant
December 17, 2018
Answered

If Else Statement not working?

  • December 17, 2018
  • 4 replies
  • 4584 views

Hey,

Before the 2019 update for After Effects, my expression for a countdown clock was working a treat. Now the If else statement seems to have had a definition change and I can't seem to find where the issue is. Does anyone have an idea of what could be happening?

Here is the original expression:

rate = -1;

clockStart = 899.97;

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);

msec = clockTime.toFixed(2).substr(-2);

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

Thanks

This topic has been closed for replies.
Correct answer P.M.B

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

}

You sure that's proper syntax?

Shouldn't it be

if(condition) {code} else {code}

???

Also AE should be telling what line the error is on.  You don;t get an error message?

4 replies

Participant
December 17, 2018

Cheers,

yea... added proper syntax and it worked again haha.

Thanks for the help

Participating Frequently
December 7, 2020

For those who are NOT code mavens, I had the exact same problem and carefully replaced line A: with line B:

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

B: if(n < 10) {return "0" +n} else {return"" + n}

And by sheer miracle, it worked! I am a novice AE user, and I know even less about AE Expressions, but if I can do it ANYBODY can do it!

Mylenium
Legend
December 17, 2018

What the others said already - it helps to adhere to proper syntax, not play it dirty and use crooked/ illegal shorthands and hope the engine will figure it out.

Mylenium

Known Participant
March 18, 2020

It would help even more if Adobe wouldn't pull the rug out from underneath us with changes like this, breaking things that were working fine previously 

Martin_Ritter
Legend
March 18, 2020

You can still switch to the old engine - the option is in project project settings.

 

Writing proper code in the first place would be the best way to handle this, of course.

 

*Martin

Martin_Ritter
Legend
December 17, 2018

Gutterfish is right. Adobe changed the expression-engine in CC2019 to a strict one.

Hold on proper syntax and it will work again.

P.M.B
P.M.BCorrect answer
Legend
December 17, 2018

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

}

You sure that's proper syntax?

Shouldn't it be

if(condition) {code} else {code}

???

Also AE should be telling what line the error is on.  You don;t get an error message?

~Gutterfish