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

If/Then statement error: Invalid token else

Community Beginner ,
Jun 21, 2019 Jun 21, 2019

Copy link to clipboard

Copied

I'm wracking my brain trying to fix this basic if/then expression. I have a text layer(name "Position (l/r") whose value I want to control the opacity of other layers. I'm using this expression on the layers whose opacity I want to control and applying it to the Opacity property:

if(thisComp.layer("Position (l/r)").text.sourceText=="r")100 else 0;

AE gives me the following error: 

SyntaxError:Unexpected token else

I've used the exact same if/then expression format in other projects (only changing the layer name) and it works fine. I've copied this expression into another project and it works fine. If I copy the expression from a working project into the current project, it doesn't work.

I'm using AE 16.1.1.1 on Windows 10.

Views

26.2K

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 , Jun 21, 2019 Jun 21, 2019

this because the new javaScript engine in AE CC 2019,,

you have 2 option to fix this, you can run the legacy ExtenScript from project settings

Screen Shot 2019-06-21 at 7.59.27 PM.png

Or put the if/else value inside curly bracket like this { 100 }else{ 50 }

Votes

Translate

Translate
Community Expert ,
Jun 21, 2019 Jun 21, 2019

Copy link to clipboard

Copied

this because the new javaScript engine in AE CC 2019,,

you have 2 option to fix this, you can run the legacy ExtenScript from project settings

Screen Shot 2019-06-21 at 7.59.27 PM.png

Or put the if/else value inside curly bracket like this { 100 }else{ 50 }

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 ,
Jun 21, 2019 Jun 21, 2019

Copy link to clipboard

Copied

Thank you!

I assume new projects are set to Javascript by default, because my old projects show "Legacy ExtendScript".

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 ,
Jun 21, 2019 Jun 21, 2019

Copy link to clipboard

Copied

option 3 is to use the new “update legacy expressions” script under file->scripts

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 ,
Apr 23, 2020 Apr 23, 2020

Copy link to clipboard

Copied

Thank you, this helped me

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 ,
Apr 29, 2020 Apr 29, 2020

Copy link to clipboard

Copied

Hi! Would you happen to know how I could save this new preset/script? I'm using a plugin/tool from 2014 that broke with the new JavaScript update, and the original creator is no longer updating it. "Updating Legacy Expressions" seems to have done the trick, but I need to save this so I don't need to do it each time I open a project. Thanks!

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 ,
Aug 13, 2021 Aug 13, 2021

Copy link to clipboard

Copied

Thank you soooo much!

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 ,
Dec 08, 2021 Dec 08, 2021

Copy link to clipboard

Copied

Thanks Roei, the "update legacy expressions" worked!

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 ,
Jan 02, 2021 Jan 02, 2021

Copy link to clipboard

Copied

Thak you, a lot!
Solution worked:

Or put the if/else value inside curly bracket like this { 100 }else{ 50 }

 

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 ,
Aug 02, 2021 Aug 02, 2021

Copy link to clipboard

Copied

This thread helped solve the issue. Thank you fine people.. much appreciate:exclamation_mark:😃

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 ,
Sep 22, 2023 Sep 22, 2023

Copy link to clipboard

Copied

LATEST

currently i have this problem woth my after effect 2023, anyone help me resolve this image_2023-09-22_225616393.png

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