# Creative Communities of the World Forums

The peer to peer support community for media production professionals.

• # Math.Max instead of if else

2 Members · 4 Posts

November 11, 2022 at 1:57 am

Hi, I have an expression I use often to scale down text once it reaches a certain length.

I have applied it a null and parented 2 text layers to it, and used an if else statement to resize according to which text reaches that length first. The 2 layers need to stay the same relative size to each other, but their animations are different, so they need to stay as seperate text layers.

Is it possible to rewrite this expression with a math.max instead of an if else. I am asking in case I have too many layers one day, here is my code as is, I have tried over and over to apply the math.max but it doesn’t work as expected;

x= thisComp.layer(“TEXT1”).sourceRectAtTime(3).width;

y= thisComp.layer(“TEXT2”).sourceRectAtTime(3).width;

a=(1920/x)*44;

b=(1920/y)*44;

xclamp= clamp(a,1,100);

yclamp= clamp(b,1,100);

if(x>y) [xclamp,xclamp]; else [yclamp,yclamp]]

thanks

• ### Dan Ebberts

November 11, 2022 at 5:21 am

I think you’d replace the last line with this:

s = Math.max(xclamp,yclamp);
[s,s]

November 11, 2022 at 2:05 pm

ya I thought so too, but it doesnt work. for some reason, it only work when both lines get to that maximum length, and even then it stops working at some point.

November 11, 2022 at 2:40 pm

ok i think i fixed it, the 1920 divided by needs to be after the math.max.

thanks so much, I wouldnt have been able to fix it without seeing yours first

x= thisComp.layer(“TEXT1”).sourceRectAtTime(3).width;

y= thisComp.layer(“TEXT2”).sourceRectAtTime(3).width;

s = Math.max(x,y);

a=(1920/s)*44;

xclamp= clamp(a,1,100);

[xclamp,xclamp]

Viewing 1 - 4 of 4 posts