Skip to main content
CardinalBags
Participant
October 25, 2018
Answered

Adding functions to expressions - source text not displaying

  • October 25, 2018
  • 4 replies
  • 4816 views

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"}

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

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

4 replies

PawSydney
Known Participant
January 4, 2019

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

PawSydney
Known Participant
January 4, 2019

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

PawSydney
Known Participant
January 4, 2019

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

Szalam
Community Expert
Community Expert
January 4, 2019

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.

Szalam
Community Expert
Community Expert
October 25, 2018

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

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
October 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

CardinalBags
Participant
October 25, 2018

Thanks. Worked like a charm. Brilliant!