Copy link to clipboard
Copied
I have copied and pasted this code from someone who it was working for, but I'm getting this error:
Error: Syntax Error: missing ) after argument list
Can someone please point out the error? I'm new to expressions but can't find it. I've bolded where AE says the problem is.
rateOfSpeed=1;
clockStartTime = thisComp.layer("Timer Duration").effect("Slider Control")("Slider")*60;
clockTimeNumber = Math.floor(clockStartTime – rateOfSpeed*time);
function addZero(n) {
if (n<10) return “0” + n else return n;
}
minutes = Math.floor(clockTimeNumber/60);
seconds = clockTimeNumber%60;
if (clockStartTime > 0 && time < clockStartTime) {
addZero(minutes) + “:” + addZero(seconds);
} else {“00:00”}
1 Correct answer
This is likely from copying code directly from a webpage. You have curly ("smart") quotes which aren't acceptable characters, but also the "-" in the "clockTimeNumber" variable isn't the proper minus. If you delete it and retype it, as well as fix the quotes, some of the errors go away. There are also a number of syntax errors that are causing issues, so a lot of things needed to be fixed here.
Copying the code from this editor should work fine now, assuming you have a layer called "Timer Dura
...Copy link to clipboard
Copied
The error is not in the bolded line, but rather in the actual function definition. The new AE expression engine introduced a while ago is much stricter and your sloppy code does not contain the proper curly brackets. Funny enough it's done correctly in the other conditional at the end. So unless you feel like switching to the legacy engine in the prefs, fix the brackets and it should work.
Mylenium
Copy link to clipboard
Copied
This is likely from copying code directly from a webpage. You have curly ("smart") quotes which aren't acceptable characters, but also the "-" in the "clockTimeNumber" variable isn't the proper minus. If you delete it and retype it, as well as fix the quotes, some of the errors go away. There are also a number of syntax errors that are causing issues, so a lot of things needed to be fixed here.
Copying the code from this editor should work fine now, assuming you have a layer called "Timer Duration" with a slider with the default name of "Slider Control" on it. Also note, this expression will only work in the new JavaScript engine and not the legacy ExtendScript engine, but judging by the error you got you're already using the new engine, so that's good.
const rateOfSpeed = 1;
const clockStartTime = thisComp.layer("Timer Duration").effect("Slider Control")("Slider") * 60;
const clockTimeNumber = Math.floor(clockStartTime - rateOfSpeed * time);
function addZero(n) {
if (n < 10) {
return "0" + n;
} else {
return n;
}
}
const minutes = Math.floor(clockTimeNumber / 60);
const seconds = clockTimeNumber % 60;
if (clockStartTime > 0 && time < clockStartTime) {
addZero(minutes) + ":" + addZero(seconds);
} else {
"00:00";
}
Copy link to clipboard
Copied
Thank you for breaking that down for me, David!
I am still learning a lot about expressions, but I know nothing about coding, so typing things the right way is something I'm going to have to figure out.
I appreciate your help.
Copy link to clipboard
Copied
You're welcome. You often have to be careful about copying code from people online—it's typically poorly formatted and uses improper syntax, but also you have to especially watch out for characters that get converted like the curly quotes.
In the default expression editor theme you're using (you can change this color scheme in the preferences), all strings (text) should be a pale red, just like the name of the null and slider in your screenshot. At the bottom, you can see the both the colon and the zeros on the last line aren't pink, indicating they aren't being evaluted as strings, which is a clear indication that those curly quotes are the source of the problem.
Additionally, there is a new Expression Engine in AE and much of the poorly formatted code online isn't supported because, as Mylenium said, the syntax is much stricter in the new engine. This prevents bad code from executing, but it also might cause confusion why an expression used to work in an old project, or it works for some people and not others. This isn't to say that you should switch back to the Legacy ExtendScript engine (you shouldn't), it just means that there's a lot to be aware of as you learn about expressions.

