ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Conditional statements with multiple values and multiple results

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Sean Kimber
Conditional statements with multiple values and multiple results
on Apr 8, 2020 at 8:10:36 pm
Last Edited By Sean Kimber on Apr 8, 2020 at 8:39:27 pm

I have another expressions question. :slightly_smiling_face: I was wondering two things about if/else conditional statements. I have 4 values. I want to say that if a is greater than b, c, & d, then the width value = x and the height value = y. (There wouldn't be a variable in the x & y spot - it would be a specific value). Then I want to do the same for b, c, & d.

My questions are:

A.) Is it possible to check which value is the greatest without having to write out if(a>b && a>c && a>d)? It's a lot of typing. I'm fine typing it for each value, but I'm wondering if there's a shortcut.

And

B.) Is it possible to have more than one result in a conditional statement? If so, how do I write it. I basically want to say, "If (a==true){width = x.width && height = y.height}," but that always produces errors. Is there a way to do this, or do I have to write the conditional statement twice, once for width and once for height?

Thank you!


UPDATE: I've tried 2 options, had some success with the first, none with the second:

1st Option:

a = thisComp.layer("TEXT").sourceRectAtTime();
b = thisComp.layer("TEXT 2").sourceRectAtTime();
c = thisComp.layer("TEXT 3").sourceRectAtTime();
d = thisComp.layer("TEXT 4").sourceRectAtTime();

if(a>=b && a>=c && a>=d){
Width = a.width;
Height=a.height;
}else if(b>a && b>c && b>d){
Width = b.width;
Height = b.height;
}else if(c>a && c>b && c>d){
Width = c.width;
Height = c.height;
}else{
Width = d.width;
Height = d.height;

p=thisComp.layer("EFFECTS").effect("box margin")("Slider");
if(Width!=0){
x=Width+p*10
}else{
x=0
}
y=Height+p;
[x,y]


Attempt 2:

a = thisComp.layer("TEXT").sourceRectAtTime();
b = thisComp.layer("TEXT 2").sourceRectAtTime();
c = thisComp.layer("TEXT 3").sourceRectAtTime();
d = thisComp.layer("TEXT 4").sourceRectAtTime();

mX = Math.max(a, b, c, d);

if(a == b && a == c && a == d){
Width = a.width;
Height = a.height;
}else{
Width = mX.width;
Height = mX.height;
}

p=thisComp.layer("EFFECTS").effect("box margin")("Slider");
if(Width!=0){
x=Width+p*10
}else{
x=0
}
y=Height+p;
[x,y]




Return to posts index

Dan Ebberts
Re: Conditional statements with multiple values and multiple results
on Apr 8, 2020 at 9:24:31 pm

You can use Math.max() to compare multiple values, like this:

Width = Math.max(a.width, b.width, c.width, d.width);

That should help simplify things.

Dan



Return to posts index

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