ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

IF...ELSE error on opacity property

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Roland Tobiasz
IF...ELSE error on opacity property
on Oct 29, 2019 at 9:53:58 pm
Last Edited By Roland Tobiasz on Oct 29, 2019 at 10:43:28 pm

Hi,

I'm just learning EA expressions and I'm stuck with a simple IF...ELSE statement that seems to be isolated to the opacity property.

Error:

"After Effects warning: Expression Disabled
Error at line 3 in property 'Opacity' of layer 1 ('Test') in comp 'Test Comp'.

Expected: ;"

var a = 1;

If (a==1){
100
} else {
0
}


I've tried putting the semicolon everywhere and I still get the same error.



Return to posts index

Dan Ebberts
Re: IF...ELSE error on opacity property
on Oct 29, 2019 at 10:46:33 pm

You have a capitalized If, it should be lower case: if

Dan



Return to posts index

Roland Tobiasz
Re: IF...ELSE error on opacity property
on Oct 29, 2019 at 11:20:12 pm

Thank you Sir! You are spot on! I was trying to figure out the error for the past 3 hours!

Maybe you could help me with the entire expression and save me a few days of trying to figure it out on my own?

I have a null layer with a Point Control effect that I am using to hold values that I have populated using a script in 1 to 10 seconds linear keyframe intervals so I have approximately 100 keyframes.

pProperty = app.project.item(6).layer("Null 1").property("Effects").property("Point Control").property("Point")[1]

I would like to linear in the opacity from 0 to 100 in 0.5 seconds if a keyframe value on pProperty is less than 500 and linear out the opacity from 100 to 0 in 0.5 seconds if a keyframe value on pProperty is >= 500.


Return to posts index


Roland Tobiasz
Re: IF...ELSE error on opacity property
on Oct 30, 2019 at 12:12:18 am

I came up with this code, which toggles between 0 and 100 when the Null 1 value changes above or below 500 but it isn't ramping the opacity over the 0.5 second duration.


fadeTime = .5;

if (thisComp.layer("Null 1").effect("Point Control")("Point")[0]>=500){
linear(time,value,value+fadeTime,0,100)
}else if (thisComp.layer("Null 1").effect("Point Control")("Point")[0]<500) {
linear(time,value-fadeTime,value,100,0);
}


Return to posts index

Dan Ebberts
Re: IF...ELSE error on opacity property
on Oct 30, 2019 at 12:35:15 am

It's a little more complicated. Something like this maybe:


fadeTime = .5;
p = thisComp.layer("Null 1").effect("Point Control")("Point");
n = 0;
if (p.numKeys > 0){
n = p.nearestKey(time).index;
if (time < p.key(n).time) n--;
if (n > 0){
if (p.key(n).value[0] >= 500){
linear(time,p.key(n).time,p.key(n).time+fadeTime,0,100);
}else{
linear(time,p.key(n).time,p.key(n).time+fadeTime,100,0);
}
}else{
p.key(1).value[0] >= 500 ? 0 : 100;
}
}else
value;



Dan



Return to posts index

Roland Tobiasz
Re: IF...ELSE error on opacity property
on Oct 30, 2019 at 12:56:35 am

Dan,

Wow!

Thank you very much!

As I said at the beginning, I am just learning so your examples are a great source for that.

If I am reading your code correctly then if p has keyframes then find the closest keyframe to the current position, read it's time and then use it in the linear function to set the start time and duration for the fade in - fade out.

Not sure what these 2 lines do:

if (time < p.key(n).time) n--;
...
p.key(1).value[0] >= 500 ? 0 : 100;


Return to posts index


Dan Ebberts
Re: IF...ELSE error on opacity property
on Oct 30, 2019 at 12:59:53 am

if (time < p.key(n).time) n--;

The nearest keyframe might not have been reached yet, you want the nearest previous keyframe.

p.key(1).value[0] >= 500 ? 0 : 100;

This is only necessary if the first keyframe is not at time = 0.


Dan



Return to posts index

Roland Tobiasz
Re: IF...ELSE error on opacity property
on Oct 30, 2019 at 1:11:48 am

Thank you.


Return to posts index

Roland Tobiasz
Re: IF...ELSE error on opacity property
on Oct 30, 2019 at 1:35:44 am

Dan,

I was testing the expression and I noticed that the change happens on the keyframe, which is a bit problematic if the keyframes are far apart and the values change significantly between them.

Here's what I am seeing:

Keyframe1 (time = 1 seconds, value = 0)
Keyframe2 (time = 10 seconds, value = 1000)

Your code changes the opacity at keyframe2 (10 seconds) although the 500 threshold was crossed at the 5 second time and ideally, that should have triggered the opacity change.

Is there a way to read the values between keyframes i.e. for each frame from the point control effect (thisComp.layer("Null 1").effect("Point Control")("Point")[0]) and use that to trigger the opacity change?


Return to posts index


Dan Ebberts
Re: IF...ELSE error on opacity property
on Oct 30, 2019 at 4:54:23 am

If the keyframes are linear, the expression could calculate where the 500 point is, but the code would be a little tricky. Do-able though, I think.

Dan



Return to posts index

Roland Tobiasz
Re: IF...ELSE error on opacity property
on Oct 30, 2019 at 5:30:51 pm

I'm still struggling to understand why this would need to be calculated.

If I put the 'app.project.item(6).layer("Null 1").property("Effects").property("Point Control").property("Point")[1]' into Source Text, the value is displayed correctly on the screen as the playhead moves along the timeline. No need to calculate it.

I would imagine that the script would want to find a frame instead of a keyframe where the value is greater than 500 and use it's time to initiate the if...then ... linear function.

So instead of looping through keyframes, loop through frames?


Return to posts index

Dan Ebberts
Re: IF...ELSE error on opacity property
on Oct 30, 2019 at 5:57:26 pm

>loop through frames?

That would be the brute-force, last-resort method, but it should work.

Dan



Return to posts index


Roland Tobiasz
Re: IF...ELSE error on opacity property
on Oct 30, 2019 at 6:13:26 pm

Thank you.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]