Copy link to clipboard
Copied
I've got thisComp.numLayers - 1 layers in my composition, plus a slider control on a null object placed above those layers. The slider control has this expression:
num = thisComp.numLayers;
seedRandom(1881);
Math.floor(random(2, num + 1));
And each other layer's opacity property has this expression:
ctrl = thisComp.layer("controller").effect("layer")("Slider");
if (ctrl == thisLayer.index) 100;
else 0;
The ideal situation is that one layer's opacity is triggered per frame. I know that sounds strange and visually upsetting out of context, but after a few time displacement effects and echos and yadayadayada, it'll look how I want it.
And the result is that at least one layer is usually being triggered every frame. But many frames are triggering two layers at once, often a frame whose index is nowhere near any of the slider's most recent past and following results, and sometimes no layers are being triggered even though the slider's value is clearly within bounds and pointing to a specific layer. Which is strange. It could be a syntax issue. I understand AE isn't quite as lax as other JS compilers out there. If I just need to put brackets around the if/else outputs, I'll just do a simple face palm and move on. I should clarify I tried this, and it did not help.
So I wanted to document this. I'll likely find a fix or workaround as I always do, but I never ask the community questions like this and feel the answers to these seemingly specialized questions could benefit someone in the future.
Try changing your first expression to this:
num = thisComp.numLayers;
f = timeToFrames(time);
seedRandom(f,true);
Math.floor(random(2, num + 1));
Dan
Copy link to clipboard
Copied
I found a similar issue and solution, though it's not a one-to-one recreation of my problem:
Copy link to clipboard
Copied
Try changing your first expression to this:
num = thisComp.numLayers;
f = timeToFrames(time);
seedRandom(f,true);
Math.floor(random(2, num + 1));
Dan
Copy link to clipboard
Copied
Thanks, Dan!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now