Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Illegal use of Reserved word – multiple If/Else statements

  • Illegal use of Reserved word – multiple If/Else statements

    Posted by Matthew Russell on November 5, 2018 at 7:30 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 && <180) {
    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;

    Alex Printz replied 7 years, 10 months ago 2 Members · 2 Replies
  • 2 Replies
  • Matthew Russell

    November 6, 2018 at 8:34 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;

  • Alex Printz

    November 7, 2018 at 5:22 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

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy