Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Syntax Change IF causes Problem – what am i missing?

  • Syntax Change IF causes Problem – what am i missing?

    Posted by Jonas Schwarzer on August 6, 2020 at 10:36 am

    Hello,

    i just changed my project from the legacy-engine to java script. I got most syntac issues fixed.
    But one IF/ELSE statement wich worked fine, just won´t run. Can someone help me to fix the problem.

    I have two sliders (w1 & w2) with two values (like 0-100) which i want to compare, and a third slider to control the animation. If one value is bigger/smaller than the other it should play the animation of the third slider (Trend_Pfeil1) via the linear-function.

    In legacy it was quite an easy code, and worked without any problems. But since the change to java i just can´t get it to run. And i think i just missed a little thing, and i am really a beginner at scripting

    I tried only the “else”- statement without condition, change other things, the last idea was to try it with an “else if”. But i get an error message that translates to: “the expression uses an non defined value (maybe your subscript of the array is out of the valid range)”.

    i tried to round the slider values with “Math.round()” or use “parseInt” because i thought maybe it is a problem with the values that are used. Or has it to do that the use of degrees with minus-numbers causes problems. Hope someone can tell me what i am missing.

    w1 = thisComp.layer("Werte_Speicher").effect("Durschnitt W1")("Schieberegler");
    w2 = thisComp.layer("Werte_Speicher").effect("Durschnitt W2")("Schieberegler");
    rotate_arrow = -90;
    if (w1 < w2){ rotate_arrow =linear(thisComp.layer("Werte_Speicher").effect("Trend_Pfeil1")("Schieberegler"),0,100,-90,-135); rotate_arrow; } if (w1 > w2){ rotate_arrow = linear(thisComp.layer("Werte_Speicher").effect("Trend_Pfeil1")("Schieberegler"),0,100,-90,-45); rotate_arrow; } else if(w1 == w2){ rotate_arrow; };

    Jonas Schwarzer replied 5 years, 9 months ago 1 Member · 1 Reply
  • 1 Reply
  • Jonas Schwarzer

    August 6, 2020 at 11:51 am

    I found the error. In my first try, in each If-condition, i had only the linear() function as return value, without adding the value to a variable (in the old legacy-engine this worked fine).
    In the new version i added, that it writes the linear function to the variable “rotate_arrow” but also added the “else if”-condition which caused another problem.
    So just by changing the “else if” condition to an “else”-condition it works fine now. Easy fix for hours of searching the internet and try hundreds of variations… So the java engine really needs you to make a much cleaner code. I post the fix bellow, but i think for most people this would be obvious.

    (P.S.:Not sure i explain it correctly, but i am trying with my noob scripting skills).

    w1 = thisComp.layer("Werte_Speicher").effect("Durschnitt W1")("Schieberegler");
    w2 = thisComp.layer("Werte_Speicher").effect("Durschnitt W2")("Schieberegler");
    rotate_arrow = -90;
    if (w1 &lt; w2){
    rotate_arrow = linear(thisComp.layer("Werte_Speicher").effect("Trend_Pfeil1")("Schieberegler"),0,100,-90,-135);
    rotate_arrow;
    }
    if (w1 > w2){
    rotate_arrow = linear(thisComp.layer("Werte_Speicher").effect("Trend_Pfeil1")("Schieberegler"),0,100,-90,-45);
    rotate_arrow;
    }
    else {
    rotate_arrow;
    }

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