Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression error trying to rotate z using index

  • Expression error trying to rotate z using index

    Posted by Jack Phillips on April 10, 2014 at 11:58 pm

    I’ve been trying to figure out why I’m getting an error but I’m stumped. I’m trying to use the index to rotate a 3D layer’s z-rotation, but I get a “Class ‘global’ has no property or method named ‘t'” error. BTW, the expression works as expected on the first 5 layers in the comp.

    Any help would be greatly appreciated.

    Thanks,

    Jack

    num=(index/5 % 1);
    if (num==.2) t=-60;
    if (num==.4) t=60;
    if (num==.6) t=-120;
    if (num==.8) t=120;
    if (num==.0) t=0;
    [t]

    Jack Phillips replied 12 years, 1 month ago 3 Members · 4 Replies
  • 4 Replies
  • James Peres

    April 11, 2014 at 2:05 am

    Hi, not sure what you are trying to do exactly, but 10/5 % 1 would be 0.02, so I don’t think it will work the way you want.

    Also, I would personally put t=0 before everything, and then put the t=[whatever] in braces, then not put t in brackets. There may be some quick shortcuts I’m not sure about but I just stick to the basic syntax.


    James

    Mac Pro 4,1 Quad Core 2.66

  • Jack Phillips

    April 11, 2014 at 11:36 am

    Hi James,

    Thanks for your response. Unfortunately, changing the code did not change the result (updated code included).

    The statement to get the “num” variable works as expected (btw, (10/5 % 1) will be 0 as the remainder of (10 divided by 5) divided by 1 is 0). The problem seems to be with the conditional statements. And the error doesn’t appear until the sixth layer in the comp upwards.

    Thanks,

    Jack

    num=(index/5 % 1);
    t = 0;
    if (num==.2) {
    t=-60
    };
    if (num==.4) {
    t=60
    };
    if (num==.6){
    t=-120
    };
    if (num==.8){
    t=120
    };

    t

  • Xavier Gomez

    April 11, 2014 at 3:50 pm

    You can try with a switch over index%5 (equivalent, but simpler than index/5 % 1):
    switch (index%5){
    case 1 : t =-60; break;
    case 2 : t = 60; break;
    case 3 : t = -120; break;
    case 4 : t = 120; break;
    default : t = 0;
    };
    t;

    Xavier

    Edit : It is quite risky to compare non integral numbers…
    You can try this: open the javascript editor (File>Scripts>Open Scrip Editor), type the line:
    6/5 % 1;
    press ‘play’ (top right area of the editor window).
    The result appears in the bottom row of the window : 0.2
    Now replace that one line code by
    (6/5 % 1) == 0.2;
    and press play again. Result ….. false 😉

  • Jack Phillips

    April 11, 2014 at 3:59 pm

    Xavier,

    This works perfectly. I didn’t even know the “switch” statement existed. Must read up on it.

    Thank you very much!

    Jack

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