Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Math.round((a/b*100)) But if “0” become “text”

  • Math.round((a/b*100)) But if “0” become “text”

    Posted by Bas V breugel on July 11, 2018 at 12:09 pm

    Hi!

    We have made this soccer template. It shows the shot accuracy in digits by dividing shots on goal with shots taken.
    But if there are 0 shots the text layer saiz “NAN”. We tried to get it to say “No shots taken”. But AE gives this projects contains expression errors

    a=parseInt(thisComp.layer("n_ShotsOnGoal").text.sourceText);
    b=parseInt(thisComp.layer("n_Shots").text.sourceText);

    if(b == 0){
    c = "No shots taken";
    } else {
    c=Math.round((a/b*100))+"%";
    }

    Bas V breugel replied 7 years, 10 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    July 11, 2018 at 1:09 pm

    Your expression works for me (I was surprised), but try changing this:

    if(b == 0){

    to this:

    if(b == “0”){

    Dan

  • Bas V breugel

    July 11, 2018 at 2:15 pm

    Thanks Dan.

    Figured out that the error was from the bar graph. It took the value fom the text.

    Now changing the expression in the scale property in the bargraph shape layer. So that the bar graph know that “No shots taken” equals “0”

    transition = 1
    xa = 0;
    xb = parseInt(thisComp.layer("Shot_Percentage").text.sourceText);
    if(!xb){
    xb=0;
    }
    y = 100;

    if(time < (inPoint+outPoint)/1){
    ease(time,inPoint,inPoint+transition,[xa,y],[xb,y]);
    }else{
    ease(time,outPoint -transition,outPoint,[xb,y],[xa,y]);
    }

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