Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions If(this OR that)… times 5.

  • If(this OR that)… times 5.

    Posted by Tim Parsons on February 20, 2023 at 4:26 pm

    I want to have an “OR” in an if/else chain using “||” . My basic setup is that I have an adjustment layer with a fill on it, and in the fill, I have an if/else expression than links to a drop down menu controller. The menu dictates which colors the fill uses, but some menu items use the same RGB values.

    So far, here’s my code:

    MENU=thisComp.layer("Null 3").effect("Brand Menu")("Menu").value;
    if(MENU == 1 || 2 || 3 || 4){
    [Blue RGBA values]
    }else if(MENU == 5){
    [Yellow RGBA values]
    }else if(MENU==6 || 7 || 8){
    [Orange RGBA values]
    }else if(MENU==9 || 10 || 11 || 12){
    [Red RGBA values]
    }else if(MENU==14){
    value
    }else{
    value
    }

    There are no errors on the expression. It returns the proper color for the first menu option, but none of the others. Every menu option shows the same color as the first menu option.

    For example, Menu items 1-4 show blue, and while Menu item 5 should show yellow, it shows blue. Menu items 6-8 should show red, but it shows blue. Same with every other menu item. Blue.

    What am I missing??

    Filip Vandueren replied 3 years, 2 months ago 3 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    February 20, 2023 at 4:52 pm

    I think the first test is messing things up. Try it this way:

    if (MENU  == 1 || MENU  == 2 || MENU  == 3 || MENU  == 4){
  • Tim Parsons

    February 22, 2023 at 3:37 pm

    THAT WORKED! Thank you SO MUCH!

  • Filip Vandueren

    February 23, 2023 at 10:30 am

    another more compact method:

    if ( [1,2,3,4].includes(MENU))  { … }

    or a switch statement:

    switch (MENU) {
    case 1:
    case 2:
    case 3:
    case 4:
    // this will trigger for 1-4
    // blue stuff
    break; // this will stop triggering other statements/conditions below
    case 5:
    // yellow
    break;
    case 6:
    case 7:
    // orange
    break; // etc. etc.

    The final “else clause would be with a

    default:

    statement, then close }

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