Copy link to clipboard
Copied
I'm trying to create the following conditional statement:
if(thisComp.layer("Controls").effect("First Slider Control")("Slider")==61
&&
if(thisComp.layer("Controls").effect("Second Slider Control")("Slider")==3
&&
if(thisComp.layer("Controls").effect("Third Slider Control")("Slider")==24)100 else 0;
I'm applying the above expression to another layer's transparency property.
First of all, is there a way to simplify the above expression?
And now to my main question:
Is there a way to include multiple values into the expression above?
For example:
I want to be able to have the layers transparency be 100 if the "Second Slider Control" value is either "1,2,3,4 or 5" and "Third Slider Control" value is either 24,30,32 or 38.
Here are some notes:
If the "First Slider Control" value is 61
and
If the "Second Slider Control" value is either 1, 2, 3, 4 or 5
and
If the "Third Slider Control" value is either 24, 30, 32 or 38
Then the layer transparency is set to 100
Any other value on any of the 3 slider controls will set the layer transparency to 0
I've been trying to do this and can't seem to figure out the right way to do it.
This would be one way:
function checkArray(theVal,theArray){
for (i = 0; i < theArray.length; i++){
if (theArray == theVal) return true;
}
return false;
}
L = thisComp.layer("Controls");
s1 = L.effect("First Slider Control")("Slider");
s2 = L.effect("Second Slider Control")("Slider");
s3 = L.effect("Third Slider Control")("Slider");
b1 = checkArray(s1,[61]);
b2 = checkArray(s2,[1,2,3,4,5]);
b3 = checkArray(s3,[24,30,32,38]);
if (b1 && b2 && b3) 100 else 0
Dan
Copy link to clipboard
Copied
This would be one way:
function checkArray(theVal,theArray){
for (i = 0; i < theArray.length; i++){
if (theArray == theVal) return true;
}
return false;
}
L = thisComp.layer("Controls");
s1 = L.effect("First Slider Control")("Slider");
s2 = L.effect("Second Slider Control")("Slider");
s3 = L.effect("Third Slider Control")("Slider");
b1 = checkArray(s1,[61]);
b2 = checkArray(s2,[1,2,3,4,5]);
b3 = checkArray(s3,[24,30,32,38]);
if (b1 && b2 && b3) 100 else 0
Dan
Copy link to clipboard
Copied
Thank you for your advice Dan. If works very well.
If I was to go further with this and modify this expression a little more how would I do the following:
if "First Slider Control" value = 61
if "Second Slider Control" value = 1
and "Third Slider Control" value = 31
the set opacity to 100 else 0
or
if "First Slider Control" value = 61
if "Second Slider Control" value = 2
and "Third Slider Control" value = 31
the set opacity to 100 else 0
or
if "First Slider Control" value = 61
if "Second Slider Control" value = 3
and "Third Slider Control" value = 24, 30, 31, 32 or 38
the set opacity to 100 else 0
or
if "First Slider Control" value = 61
if "Second Slider Control" value = 4
and "Third Slider Control" value = 23, 24, 25, 30, 31, 32, 37, 38 or 39
the set opacity to 100 else 0
or
if "First Slider Control" value = 61
if "Second Slider Control" value = 5
and "Third Slider Control" value = 30, 31 or 32
the set opacity to 100 else 0
Copy link to clipboard
Copied
Maybe something like this:
sets = [[61,1,31],
[61,2,31],
[61,3,24], [61,3,30], [61,3,31], [61,3,32], [61,3,38],
[61,4,23], [61,4,24], [61,4,25], [61,4,30], [61,4,31], [61,4,32], [61,4,37], [61,4,38], [61,4,39],
[61,5,30], [61,5,31], [61,5,32]];
function checkSets(v1,v2,v3){
for (i = 0; i < sets.length; i++){
if ((sets[0] == v1) && (sets[1] == v2) && (sets[2] == v3)) return true;
}
return false;
}
L = thisComp.layer("Controls");
s1 = L.effect("First Slider Control")("Slider");
s2 = L.effect("Second Slider Control")("Slider");
s3 = L.effect("Third Slider Control")("Slider");
if (checkSets(s1,s2,s3)) 100 else 0
Dan
Copy link to clipboard
Copied
This is great. It worked. Thank you Dan.
Copy link to clipboard
Copied
The syntax is if (A && B), not if (A) && if (B)
For your main question, in modern javascript there is a pretty simple and concise way to do what you want, but in Adobe's outdated js it'll be quicker to write the full stuff than to try to be smart.
This should work:
L = thisComp.layer("Controls");
a = L.effect("First Slider Control")("Slider").value;
b = L.effect("Second Slider Control")("Slider").value;
c = L.effect("Third Slider Control")("Slider").value;
if ((a==61) && (b==1||b==2||b==3||b==4||b==5) && (c==24||c==30||c==32||c==38)) 100 else 0;
Xavier
Copy link to clipboard
Copied
Thank you very much, Xavier. It worked as well. It is very interesting to see how an expression can be written a different way.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more