Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions AE2019 – Why does using “index” in an if statement throw an undefined value error?

  • AE2019 – Why does using “index” in an if statement throw an undefined value error?

    Posted by Karl Mochel on November 9, 2018 at 4:43 am

    Trying to use “index” in an If statement seems to throw an error.

    This project contains an expression error: error 1 of 1
    Error at line 1 in property ‘Opacity’ of layer 3 ‘Maps_AK.ai’ in comp ‘States’. Undefined value used in expression (could be an out of range array subscript?), an expression was disabled as a result of an error.

    – Error thrown in both forms of code below. In the 2nd form, 1st line has no error, but uncommenting the second gives the error:
    – “index” by itself returns a value (checked with Text layer pick-whipped to the attribute.
    – “thisComp.layer(“Control”).effect(“Slider Control”)(“Slider”)” has been pick-whipped from Effect Control.

    //Both forms of this get same error.
    // 1st form...
    if (thisComp.layer("Control").effect("Slider Control")("Slider") == index) 100 else 0;
    // 2nd form...
    selected_state = thisComp.layer("Control").effect("Slider Control")("Slider").value;
    if (selected_state == index) 100 else 0;

    Karl Mochel replied 7 years, 6 months ago 3 Members · 6 Replies
  • 6 Replies
  • Nathaniel Logan

    November 9, 2018 at 8:25 am

    I guess its because AE2019 by default use “JavaScript” as the “Expression Engine” change the Expression engine from JavaScript to “ExtendedScript” hope this might fix the issue.

    To change the Expression Engine in AE2019 GoTo –>File–>ProjectSettings—>Expression

    Vim

  • Alex Printz

    November 9, 2018 at 3:21 pm

    Try changing it to thisLayer.index; I’m not really sure the change but I’m sure it has to do with how the new javascript engine requires a more precise reference. Index ought to call that layer’s index already, but there’s been a few smaller, undocumented changes already noticed.

    Alex Printz
    Mograph Designer

  • Karl Mochel

    November 9, 2018 at 7:04 pm

    So… {} around the {then/else statements} fixed this.

    // 1st form…
    if (thisComp.layer(“Control”).effect(“Slider Control”)(“Slider”) == index) {100} else {0};

    // 2nd form…
    selected_state = thisComp.layer(“Control”).effect(“Slider Control”)(“Slider”).value;
    if (selected_state == index) {100} else {0};

    The original code from this thread didn’t have them so I didn’t think to look at that as a problem.
    https://forums.creativecow.net/docs/forums/post.php?forumid=2&postid=986190&univpostid=986190&pview=t

  • Alex Printz

    November 9, 2018 at 7:56 pm

    ah okay, it was slider.value

    Alex Printz
    Mograph Designer

  • Alex Printz

    November 9, 2018 at 7:57 pm

    that is,

    if (thisComp.layer("Control").effect("Slider Control")("Slider").value == index) {100} else {0};

    Alex Printz
    Mograph Designer

  • Karl Mochel

    November 9, 2018 at 8:08 pm

    the .value makes no difference…

    Tried it with and without and it worked both ways.

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