Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects linking a conditional statement to a variable? expression syntax

  • linking a conditional statement to a variable? expression syntax

    Posted by Anna Hahn on March 5, 2021 at 8:02 pm

    Hello!

    I am trying to make it so that the variable ‘rates’ is set to 500 if the variable ‘temp’ is above 60, and rates is set to 150 if temp is below 60

    rates = if(temp>60){500} else {150}

    When I use that syntax it fails

    My entire syntax is:

    temp = thisComp.layer(“Audio Amplitude”).effect(“Both Channels”)(“Slider”)/30;

    rates = if(temp>60){500} else {150}

    How do I fix the definition of ‘rates’ so that it works properly?

    Walter Soyka replied 5 years, 2 months ago 2 Members · 1 Reply
  • 1 Reply
  • Walter Soyka

    March 5, 2021 at 8:45 pm

    If/else is for branching the flow of execution, not for evaluation. In other words, you use if/else to decide what statements to execute, not what value to return.

    Here’s how to do it with if/else:

    if (temp > 60) { 
    rates = 500;
    } else {
    rates = 150;
    }

    There’s also an operator called the “conditional operator” or “ternary operator” that works more the way you where thinking — if an expression evaluates true, it returns the first specified value, and if not, it returns the second. It’s written using a question mark and a colon, and here’s how it would work in this case:

    rates = (temp > 60) ? 500 : 150;

    If/else can do a lot more than this single evaluation, but it’s as compact. The conditional operator is much more limited, but quite compact.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy