Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Switching Opacity of Layers with a Randomized Slider Controller

New Here ,
Jul 28, 2019 Jul 28, 2019

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.

TOPICS
Expressions
774
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 29, 2019 Jul 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

Translate
New Here ,
Jul 29, 2019 Jul 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 29, 2019 Jul 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 30, 2019 Jul 30, 2019
LATEST

Thanks, Dan!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines