Skip to main content
idolum
Inspiring
August 10, 2021
Question

Expression error, beating my head

  • August 10, 2021
  • 2 replies
  • 722 views

In an expression I'm trying to access a layer by index based on a calculation:

laynum = (index-1) - Math.floor(time);
craplayer = thisComp.layer(laynum);

but I keep getting the error "layer index -1 out of range" on that second line -- yet if I return laynum in my expression to look at the value, it's 3.0 which is correct in my case (expression is on a numeric property on layer 4, while sitting on frame 0 of the comp.)

 

If I do:

laynum = 3.0;

instead of my calculation, it works fine. I'm just not seeing what the difference is, why this isn't working. I'm using the Javascript expression engine, not the old ExtendScript.

This topic has been closed for replies.

2 replies

Dan Ebberts
Community Expert
Community Expert
August 10, 2021

With your expression on layer 4, when time gets to 3 seconds laynum will be 0 which will make layer(laynum) generate that error.

idolum
idolumAuthor
Inspiring
August 10, 2021

Well, nevermind, I guess.

After messing around more trying to figure out what the fail was, it's inexplicably started working without changing the substance of anything.

 

I'd delete this thread but apparently we're not allowed.