-
If/Else Conditional with an Array
Hi Guys. I’ve worked out a solution for my problem, but I feel it’s convoluted and unnecessarily clumsy. I stumbled across whispers and shadows of being able to use an array with If/Else conditional statements, but haven’t found anything that really helped me learn more. I’m hoping someone here could shed some light on this for me.
Here’s the story…
I have a “statistics box” made up of multiple columns and rows. The largest configuration is 5 rows x 3 columns. The smallest configuration is 1 row x 1 column. I have one text layer named “Number of Stats Categories” and another text layer named “Number of Columns.” I use the input on these two text layers to dynamically determine the size and position of the “statistics box.”
Below is the expression I have on Position. It’s basically just a bunch of If/Else statements. One If/Else statement for every possible configuration between 5×3 and 1×1. So…if 5×3, position = [x1,y1] … if 5×2, position = [x2,y2], etc, etc etc.
As you can see below my expression is pretty darn long. That being said it is working really well. It’s doing exactly what I wanted it to do. However, I feel there is probably a better way to do this and I’d love to learn of a new, better method if it’s out there.
I’ve added some images to this post as well so you can see an example of the dynamic scaling and positioning based on the input for Number of Stats Categories and Number of Columns. The images are for a 5×3 stats box and a 3×2 stats box.
StatsCats = thisComp.layer("Number of Stats Categories").text.sourceText;
NumCol = thisComp.layer("Number of Columns").text.sourceText;
if (StatsCats == 5 && NumCol == 3) {
[1300,575];
} else if (StatsCats == 5 && NumCol == 2) {
[1550,575];
} else if (StatsCats == 5 && NumCol == 1) {
[1700,575];
} else if (StatsCats == 4 && NumCol == 3) {
[1300,635];
} else if (StatsCats == 4 && NumCol == 2) {
[1550,635];
} else if (StatsCats == 4 && NumCol == 1) {
[1700,635];
} else if (StatsCats == 3 && NumCol == 3) {
[1300,695];
} else if (StatsCats == 3 && NumCol == 2) {
[1550,695];
} else if (StatsCats == 3 && NumCol == 1) {
[1700,695];
} else if (StatsCats == 2 && NumCol == 3) {
[1300,740];
} else if (StatsCats == 2 && NumCol == 2) {
[1550,740];
} else if (StatsCats == 2 && NumCol == 1) {
[1700,740];
} else if (StatsCats == 1 && NumCol == 3) {
[1300,795];
} else if (StatsCats == 1 && NumCol == 2) {
[1550,795];
} else if (StatsCats == 1 && NumCol == 1) {
[1700,795];
} else { [1300,575]; }Sample Images

