Skip to main content
Participant
January 4, 2023
Answered

Error: Undefined value used in expression (could be an out of range array subscripte?)

  • January 4, 2023
  • 2 replies
  • 5447 views
Hello,help me please. 
I am making an animation of a chart bar that changes its size and color depending on the value.
I used the slider control, I tied everything, the size changes depending on the value,
but it doesn't work at all with the color. It keeps giving the same error
Error: Undefined value used in expression (could be an out of range array subscripte?)
The error appears at 70%.
But he always chooses the wrong color.
Please help me, how to solve this problem?




 

This topic has been closed for replies.
Correct answer Dan Ebberts

The key to that type of cascading logic is using else if, like this:

 

r = thisComp.layer("test").effect("Slider Control")("Slider");
if (r <= 30)
  effect("low")("Color")
else if (r < 70)
  effect("Middle")("Color")
else
  effect("High")("Color");

 

2 replies

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
January 4, 2023

The key to that type of cascading logic is using else if, like this:

 

r = thisComp.layer("test").effect("Slider Control")("Slider");
if (r <= 30)
  effect("low")("Color")
else if (r < 70)
  effect("Middle")("Color")
else
  effect("High")("Color");

 

Participant
January 5, 2023

Thanks for the help, it worked!

Mylenium
Legend
January 4, 2023

Your code also makes no sense because the compare operator for the 70% rule is the wrong way, so the criteria is never met. It has to be >=, not <=. Also consider actually polishing yoru sloppy code. If statements are supposed to have else{} fallbacks and the new expression engine is sensitive to that. Refer to this:

 

Syntax differences between the JavaScript and Legacy ExtendScript expression engines in After Effects 16.0.

 

Mylenium