Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions if/else in an array

  • if/else in an array

  • Craig Kristensen

    March 23, 2020 at 2:35 pm

    I have 2 slider values “h” and “a” and a range of values in an array “i”.
    I would like to check if the slider values are included in the array.

    What am I missing here?

    Stay safe,
    Craig

    h = thisComp.layer("CONTROLLER").effect("Home")("Slider");
    a = thisComp.layer("CONTROLLER").effect("Away")("Slider");
    i = [1, 6, 11, 12, 16, 17, 20, 21, 22, 23, 25, 26, 27, 28, 30, 32];

    if ( h == i ) {
    100
    }
    else if ( a == i ) {
    100
    }
    else 0;

  • Andrei Popa

    March 23, 2020 at 4:14 pm

    Hi Craig.
    If you have AE 2019+, you can use the includes() function:

    h = thisComp.layer("CONTROLLER").effect("Home")("Slider");
    a = thisComp.layer("CONTROLLER").effect("Away")("Slider");
    i = [1, 6, 11, 12, 16, 17, 20, 21, 22, 23, 25, 26, 27, 28, 30, 32];
    i.includes(h) || i.includes(a) ? 100 : 0

    Older AE don’t have includes() defined so you have to make a similar function:

    function arrayIncludes(arr,el){
    for(var i=0; i

    Andrei
    My Envato portfolio.

  • Craig Kristensen

    March 23, 2020 at 6:44 pm

    Andrei to the rescue again!
    Thanks Andrei, it worked perfectly. Although the first expression did not work in AE 2020, but the second expression worked like a charm!

    Thanks again!
    Stay safe.

  • Andrei Popa

    March 24, 2020 at 9:46 am

    It’s strange that it did not work in AE 2020. Maybe you had your project expressions engine set to Legacy ExtendScript.
    You can check that by going in File>Project Preferences>Expressions and set Engine to Legacy ExtendScript.

    I’m telling you this because in case you want to use any of the features introduced after AE 2018, you need to have the engine set to JavaScript.

    Andrei
    My Envato portfolio.

  • Craig Kristensen

    March 24, 2020 at 10:32 am

    My project settings was set to “Legacy ExtendScript”. But the new version still does not work, even after I have set the project to “JavaScript”.

    But the first expression still works perfectly 🙂

Viewing 1 - 5 of 5 posts

Log in to reply.

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