ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Illegal use of Reserved word - multiple If/Else statements

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Matthew Russell
Illegal use of Reserved word - multiple If/Else statements
on Nov 5, 2018 at 7:30:34 pm

So I have an index based expression applied to rotation so that when I duplicate that layer it keeps the layers split evenly spread on 360 degrees. Which works well.

I'm adding an expression to the X position so that when I duplicate the layers I can control the width of the circle depending on its rotation value. Since each layer's rotation changes based on how many layers I have, I have four If/Else conditions driving the value. I'm taking that value and multiplying it by a slider. My hopes are that the Top and bottom layer (0º and 180º) stay put, while the further right and left (90º and 270º) the more that layer is effect by my slider value.

Basically I'm trying to get these values, based on the layers rotation. And use those values as it's factor to spread out more exponentially.
12863_scalexposbasedonrotation.png.zip

Here is the expression

I hope this makes sense.

Rot = transform.rotation;
Ctrl = thisComp.layer("Controller").effect("Width")("Slider");
Factor = if(Rot >0 && &lt;180) {
Rot;
} else if(Rot >90 && &lt;180) {
180 - Rot;
} else if(Rot >18 && &lt;270) {
180 - Rot;
} else if(Rot >270 && &lt;360) {
(360 - Rot)*-1;
} else

value;

Factor * Ctrl;


Return to posts index

Matthew Russell
Re: Illegal use of Reserved word - multiple If/Else statements
on Nov 6, 2018 at 8:34:25 am
Last Edited By Matthew Russell on Nov 6, 2018 at 8:37:09 am

After doing some research I see that I cannot have my If/else statement inside of a variable like I had. As well as after the && I needed to add back in the "Rot" variable.

And also I pasted my code wrong in the forum :P.


//Old expression
Rot = transform.rotation;
Ctrl = thisComp.layer("Controller").effect("Width")("Slider");
Factor = if(Rot >0 && <90) {
Rot;
} else if(Rot >90 && <180) {
180 - Rot;
} else if(Rot >18 && <270) {
180 - Rot;
} else if(Rot >270 && <360) {
(360 - Rot)*-1;
} else

value;

Factor * Ctrl;



So instead I moved my slider controller into the If/else. And I fixed some of my math. Plus the 90º and 270º needed their own statements.
If anybody has a cleaner / better way of doing this please let me know. I've been trying my hardest to write everything from scratch and I am getting better, but i know I may be doing things the long and hard route. Haha


//New Code
Rot = transform.rotation.value;
Ctrl = thisComp.layer("Controller").effect("Width")("Slider");
if (Rot >0 && Rot <90) {
(Rot * Ctrl);
} else if(Rot == 90) {
(Rot)* Ctrl;
} else if(Rot >90 && Rot <180) {
(180 - Rot)* Ctrl;
} else if(Rot >180 && Rot <270) {
(180 - Rot)* Ctrl;
} else if(Rot == 270) {
(-90)* Ctrl;
} else if(Rot >270 && Rot <360) {
(360 - Rot)*-1 *Ctrl;
} else
0;


Return to posts index

Alex Printz
Re: Illegal use of Reserved word - multiple If/Else statements
on Nov 7, 2018 at 5:22:08 pm

After effects does not register "else if" statements. You would just want to put a series of if statements in a tree, swap out the variables, or use a switch case.


R = transform.rotation;
C = thisComp.layer("Controller").effect("Width")(1);


switch(true){

case 0 < R && R <= 90:
R *= C;
break;

case 90 < R && R < 180:
R = (180 - R) * C;
break;

case 180 < R && R < 270:
R = (180 - R) * C;
break;

case R == 270:
R = C * -90;
break;

case 270 < R && R < 360:
R = -(360 - R) * C;
break;

default:
R = 0;
}

R


You might want to check all of your statements as I see some gaps (R < 0, R=180, R<=360, etc.)

Alex Printz
Mograph Designer


Return to posts index

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