ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Math.round((a/b*100)) But if "0" become "text"

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Bas v Breugel
Math.round((a/b*100)) But if "0" become "text"
on Jul 11, 2018 at 12:09:21 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))+"%";
}


Return to posts index

Dan Ebberts
Re: Math.round((a/b*100)) But if "0" become "text"
on Jul 11, 2018 at 1:09:16 pm

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

if(b == 0){

to this:

if(b == "0"){



Dan



Return to posts index

Bas v Breugel
Re: Math.round((a/b*100)) But if "0" become "text"
on Jul 11, 2018 at 2:15:58 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]);
}


Return to posts index

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