FORUMS: list search recent posts

I know I'm missing something simple - Opacity Controlled by Slider Trigger

FAQ   •   VIEW ALL
 I know I'm missing something simple - Opacity Controlled by Slider Trigger on Aug 7, 2016 at 1:19:54 am

I have a text layer with a slider control that controls the Source Text over time (say 1 min) from 1975 to 2016. I have an object with an in point at the same time as the text layer. I want the opacity to be 0 until the slider control is greater than or equal to 1980, at which point I want the opacity to change from 0 to 100 over 1 second.

I can get it to stay 0 until the slider reaches 1980, but then it jumps to 100% the next frame. I'm sure the problem is with the second and third argument with linear(). I'm sure it's simple, but I've been beating my head against the wall and I'm starting to bleed. Please help.

This is the code:

Thanks!

```opacityMin = 0; opacityMax = 100; slider = Math.round(thisComp.layer("1975").effect("Slider Control")("Slider")); date = 1980; animateIn = linear(time, time, time+1, opacityMin, opacityMax); if(slider >= date) {animateIn} else {0}```

 Re: I know I'm missing something simple - Opacity Controlled by Slider Triggeron Aug 7, 2016 at 2:32:43 am

The missing piece to the puzzle is when the slider reached 1980. If the current value is less than 1980, no problem, but if it's greater than 1980 the expression has to figure out how long ago it reached 1980. If the slider animation is linear, you might be able to calculate it based on the rate of change and the current value. Alternatively, you might put a marker there. Worst case, your expression will need to loop back in time, frame-by-frame, until it finds the frame where the value went from below 1980 to above 1980.

Dan

 Re: I know I'm missing something simple - Opacity Controlled by Slider Triggeron Aug 7, 2016 at 1:13:01 pm

I had an idea when I woke up but it didn't work either. I don't really understand what you mean by loop back to find the first frame. Could you show me an example script?

The goal is so that if I retime the slider, all the elements fade in at the right time, as determined by the text layer counting up. I don't know how to tell it "now" and "now + 1sec." It seems like there should be some way to do that. There's a javascript function Date.now(), but it doesn't seem to work either.

Is there any way to step through the code and see what values the variables are being assigned? When I program in Java on NetBeans, I can step through the code line by line and make sure what variable is getting what value and why. I don't see a way to do that in AE. It's kinda like using a 1990s compiler that won't tell you your errors until you compile.

Anyway, this is due tomorrow, so worst case I'll just time it by hand, but I was hoping to have things change their timing dynamically based on what I do to the slider in & out.

```opacityMin = 0; opacityMax = 100; slider = Math.round(thisComp.layer("1975").effect("Slider Control")("Slider")); date = 1980; now = 0; animateIn = linear(time, now, now+1, opacityMin, opacityMax); if(slider >= date) {now = time; animateIn} else {0}; Alternate: opacityMin = 0; opacityMax = 100; slider = Math.round(thisComp.layer("1975").effect("Slider Control")("Slider")); date = 1980; now = 0; animateIn = linear(time, now, now+1, opacityMin, opacityMax); if(slider >= date) {now = Date.now(); animateIn} else {0};```

 Re: I know I'm missing something simple - Opacity Controlled by Slider Triggeron Aug 7, 2016 at 2:39:25 pm

The problem is that AE expressions are evaluated newly for every single frame. Variable values are not remembered from one frame to the next.

Thus, if you are at a frame where the slider value is above your threshold value, you need a loop that counts back the number of frames you have in one second in your comp and checks each frame for the slider value to see if it rose above your threshold value during the last second.

Kalleheikki Kannisto
Senior Graphic Designer

 Re: I know I'm missing something simple - Opacity Controlled by Slider Triggeron Aug 7, 2016 at 2:50:40 pm

Okay that's helpful. I want to work this out, but I don't have the time to make this delivery. After my time frees up I'll come back, work on it, and post a solution if I can find it.

Thanks!

 Re: I know I'm missing something simple - Opacity Controlled by Slider Triggeron Aug 7, 2016 at 2:55:17 pmLast Edited By Kalle Kannisto on Aug 7, 2016 at 2:57:20 pm

Like so:

```year = Math.floor(effect("Slider Control")("Slider")); threshold = 1980; fps = 1/thisComp.frameDuration; t = 100; if (year < threshold) { t = 0 } else { for (i = 0; i < fps; i++){ if (Math.floor(effect("Slider Control")("Slider").valueAtTime(time-i/fps))<threshold){ t = (100/fps)*i; break } } } t```

Kalleheikki Kannisto
Senior Graphic Designer