ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

AE2019 - Why does using "index" in an if statement throw an undefined value error?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Karl Mochel
AE2019 - Why does using "index" in an if statement throw an undefined value error?
on Nov 9, 2018 at 4:43:16 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;


Return to posts index

Vimal Kumar
Re: AE2019 - Why does using "index" in an if statement throw an undefined value error?
on Nov 9, 2018 at 8:25:02 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


Return to posts index

Alex Printz
Re: AE2019 - Why does using "index" in an if statement throw an undefined value error?
on Nov 9, 2018 at 3:21:27 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


Return to posts index


Karl Mochel
Re: AE2019 - Why does using "index" in an if statement throw an undefined value error?
on Nov 9, 2018 at 7:04:55 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...


Return to posts index

Alex Printz
Re: AE2019 - Why does using "index" in an if statement throw an undefined value error?
on Nov 9, 2018 at 7:56:50 pm

ah okay, it was slider.value

Alex Printz
Mograph Designer


Return to posts index

Alex Printz
Re: AE2019 - Why does using "index" in an if statement throw an undefined value error?
on Nov 9, 2018 at 7:57:50 pm

that is,

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

Alex Printz
Mograph Designer


Return to posts index


Karl Mochel
Re: AE2019 - Why does using "index" in an if statement throw an undefined value error?
on Nov 9, 2018 at 8:08:47 pm

the .value makes no difference...

Tried it with and without and it worked both ways.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]