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

Adding functions to expressions - source text not displaying

New Here ,
Oct 25, 2018 Oct 25, 2018

Copy link to clipboard

Copied

I am very new to after effects and writing expressions, however I do code in other languages so I have a basic understanding of code structure and I understand what After effects coding is trying to do when I read a sample.

My problem is that any expression containing a function call stops appearing on screen. The layer is still there, it's just not evaluating the function and thus the output is null and thus nothing is presented on screen.

If I remove the function declaration and the call to the function from the code, the remainder of the code executes without issue, so I can definitely say the issue is with functions in general or the specific code. I have copied and pasted code from verified working projects into my code, but still same result.

This makes me think the problem is at the system level. Is there a project setting that needs to be enabled for functions to work properly? Just updated AE to CC2019 (Version 16.0.0, build #235) I have not tried coding in AE before this version so cant specifically tag this to an upgrade...

Code I am specifically using for this (countdown timer). Problem is not isolated to this code. I can write simpler functions and none of them work either.

duration=thisComp.layer("InputDuration").effect("Slider Control")("Slider");

countdown = Math.floor(duration-time);

minutes = Math.floor(countdown/60);

seconds = countdown%60;

function addZero(n) {

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

if(duration > 0 && time < duration){
"Time Remaining: " + minutes + ":" + addZero(seconds);
} else {"Time Remaining: 0:00"}

TOPICS
Expressions

Views

4.1K

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

Community Expert , Oct 25, 2018 Oct 25, 2018

If you're using the newest version of AE, the if/else construct in your function will generate an error and the error message may not show. Try changing your function to this:

function addZero(n) {

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

}

Dan

Votes

Translate

Translate
LEGEND ,
Oct 25, 2018 Oct 25, 2018

Copy link to clipboard

Copied

I'll get a moderator to move this thread to the After Effects Expressions​ forum. It's a bit more specialized.

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 Expert ,
Oct 25, 2018 Oct 25, 2018

Copy link to clipboard

Copied

If you're using the newest version of AE, the if/else construct in your function will generate an error and the error message may not show. Try changing your function to this:

function addZero(n) {

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

}

Dan

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
New Here ,
Oct 25, 2018 Oct 25, 2018

Copy link to clipboard

Copied

Thanks. Worked like a charm. Brilliant!

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
Participant ,
Aug 05, 2021 Aug 05, 2021

Copy link to clipboard

Copied

LATEST

Hi Dan,

Thanks a lot, no wonder I copied the original as below and error message.

function addZero(n) {

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

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 ,
Jan 04, 2019 Jan 04, 2019

Copy link to clipboard

Copied

took me 3 hour finding this answer and EXACTLY the same issue. (NOT HELPED AS ADDZERO SEEMS TO BE MOVED FRM FORUM TO FORUM)

     HEY ADOBE IF YOU ARE GOING TO MAKE CHANGES TO CODE HOW ABUT YOU ACTUALLY TELL US ABOUT IT.....

IMAGINE THERE ARE 1,000S OF CLOCK  / COUNTDOWN TUTORIALS ONLINE THAT ARE NOW USELESS, AND 100,000 OF PISSED OF PEOPLE.....

CAPS AND ANY INFERENCE FROM IT THOROUGHLY INTENDED

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 ,
Jan 04, 2019 Jan 04, 2019

Copy link to clipboard

Copied

Alternatively, you can switch your AE's project from using the new expression engine to using the legacy engine and things will still work just fine.

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
Engaged ,
Jan 04, 2019 Jan 04, 2019

Copy link to clipboard

Copied

HEY ADOBE IF YOU ARE GOING TO MAKE CHANGES TO CODE HOW ABUT YOU ACTUALLY TELL US ABOUT IT.....

They did...

Syntax differences between the JavaScript and Legacy ExtendScript expression engines in After Effect...

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 ,
Jan 04, 2019 Jan 04, 2019

Copy link to clipboard

Copied

well they made a web page but not  Flag any notifications when the new version of the programme opens. 

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 ,
Jan 04, 2019 Jan 04, 2019

Copy link to clipboard

Copied

this is a better syntax as the sentence is still readable, plenty of people looking for answer on the forums...

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

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

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