Skip to main content
Participant
February 3, 2022
Question

Syntax error unexpected token else

  • February 3, 2022
  • 1 reply
  • 3514 views

Hello

 

My apologies I am a beginner with expressions. I can't figure out why I am getting an error for this line:

 

if(comp("Final comp").layer("Control layer").effect("Glitches on/off")("ADBE Checkbox Control-0001")==1) 50 else 0;

 

Any insight would be much appreciated.

1 reply

Mylenium
Legend
February 3, 2022

Conditional statements require curly brackets:

 

if (condition)

{do A}

else

{do B}

 

The sloppy syntax you are using is only supported by the legacy expression engine, but since it's deprtecated and one day will simply disappear you better learn how to do things correctly from the outset. It's also good practice to funnel references to controls into their own variables before using them in the code:

 

mGlitch=comp("Final comp").layer("Control layer").effect("Glitches on/off")("ADBE Checkbox Control-0001");

 

if (mGlitch == 1)

{50}

else

{0}

 

Mylenium

Participant
February 10, 2024

Thank you for the info, but why the patronizing tone? Why can't you just point out the correct syntax? The one in the original post can be found all around the web in examples, how should one supposed to know that it's "sloppy" whatever that means.


In C# for example, which is a high level language, you can write conditional assigments like this:
result = control == 1 ? 50 : 0;
Is the tenary conditional operator also sloppy?
This is the attitude why people prefer chatgpt over these forums, be it stackoverflow or similar technical platforms. Nobody needs the patronizing, finger-waging, superiority-complex driven lectures. All the some actual information can be presented without any of this nonsense, as chatgpt demonstrates it.