Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
With your expression on layer 4, when time gets to 3 seconds laynum will be 0 which will make layer(laynum) generate that error.