Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How do I create a conditional statement with multiple values

Explorer ,
Mar 15, 2017 Mar 15, 2017

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.

TOPICS
Expressions
6.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 15, 2017 Mar 15, 2017

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

Translate
Community Expert ,
Mar 15, 2017 Mar 15, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 15, 2017 Mar 15, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 15, 2017 Mar 15, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 15, 2017 Mar 15, 2017

This is great. It worked. Thank you Dan.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 15, 2017 Mar 15, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 15, 2017 Mar 15, 2017
LATEST

Thank you very much, Xavier. It worked as well. It is very interesting to see how an expression can be written a different way.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines