Skip to main content
Participant
July 28, 2019
Answered

Switching Opacity of Layers with a Randomized Slider Controller

  • July 28, 2019
  • 1 reply
  • 820 views

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.

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

Try changing your first expression to this:

num = thisComp.numLayers;

f = timeToFrames(time);

seedRandom(f,true); 

Math.floor(random(2, num + 1));

Dan

1 reply

blnwrlyAuthor
Participant
July 29, 2019

I found a similar issue and solution, though it's not a one-to-one recreation of my problem:

Re: Time remap to change opacity

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
July 29, 2019

Try changing your first expression to this:

num = thisComp.numLayers;

f = timeToFrames(time);

seedRandom(f,true); 

Math.floor(random(2, num + 1));

Dan

blnwrlyAuthor
Participant
July 30, 2019

Thanks, Dan!