Skip to main content
Participant
December 27, 2022
Answered

Countdown timer expression error

  • December 27, 2022
  • 2 replies
  • 1926 views

I'm trying to make a countdown timer from text, counting down from 10 minutes. I'm using an expression on a Slider Control that has always worked but it seems like it doesn't work with the latest update.

 

This is the expression I'm using: 

slider = Math.round(effect("Slider Control")("Slider"))      

sec = slider%60 

min = Math.floor(slider/60) 

function addZero(n){ if (n<10) return "0" + n else return n } 

addZero(min) + ":" + addZero(sec)

 

I got the error on line 4:'' Error; SyntaxError; Unexpected 'else'

 

If anyone has any suggestions I would really appraciate the help! 

This topic has been closed for replies.
Correct answer Mylenium

All explained here:

 

https://helpx.adobe.com/after-effects/using/legacy-and-extend-script-engine.html

 

Sloppy expressions are no longer acceptable. Your if()else{} statement needs to be properly encased/ terminated with curly brackets. Reformatting also helps to detect such errors:

 

slider = Math.round(effect("Slider Control")("Slider"))      

sec = slider%60 
min = Math.floor(slider/60) 

function addZero(n)
{
if(n<10)
{return "0"+n}
else
{return n}
} 

addZero(min) + ":" + addZero(sec)

 

Mylenium

2 replies

Mylenium
MyleniumCorrect answer
Legend
December 27, 2022

All explained here:

 

https://helpx.adobe.com/after-effects/using/legacy-and-extend-script-engine.html

 

Sloppy expressions are no longer acceptable. Your if()else{} statement needs to be properly encased/ terminated with curly brackets. Reformatting also helps to detect such errors:

 

slider = Math.round(effect("Slider Control")("Slider"))      

sec = slider%60 
min = Math.floor(slider/60) 

function addZero(n)
{
if(n<10)
{return "0"+n}
else
{return n}
} 

addZero(min) + ":" + addZero(sec)

 

Mylenium

Participant
December 27, 2022

Thank you!