• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

If Else Statement not working?

Community Beginner ,
Dec 16, 2018 Dec 16, 2018

Copy link to clipboard

Copied

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

Views

3.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Dec 17, 2018 Dec 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?

Votes

Translate

Translate
People's Champ ,
Dec 17, 2018 Dec 17, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Dec 17, 2018 Dec 17, 2018

Copy link to clipboard

Copied

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

Hold on proper syntax and it will work again.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 17, 2018 Dec 17, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 18, 2020 Mar 18, 2020

Copy link to clipboard

Copied

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 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Mar 18, 2020 Mar 18, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 17, 2018 Dec 17, 2018

Copy link to clipboard

Copied

Cheers,

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

Thanks for the help

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 07, 2020 Dec 07, 2020

Copy link to clipboard

Copied

LATEST

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines