Copy link to clipboard
Copied
Hi!
Here is my issue; there are two dropdown menus with 2 sub menus for both and an animated layer. i want to use dropdown menus to show or hide this layer in this way, if i selected, first sub menu of first dropdown menu and first sub menu of second drop down menu, the animated layer will hide (or show).
here is what i use for this. but in this way, i did not get what i want.
var menu1 = comp("kj v1").layer("controller").effect("kac tl")("Menu")
var menu2 = comp("kj v1").layer("controller").effect("kacinci soru")("Menu")
if (menu1 == 1) {100} else {0}
if (menu2 == 1) {100} else {0}
in this way, it is working perfectly for menu 2 but not for menu1. i need to combine if menu1 and if menu2 in the same command. Thank you!
First of all, you should start using semicolons 😉
Did I get you right, that there a two conditions to trigger opatity: menu1 AND menu2 must be selected?
Then you have to write it this way:
if (menu1 == 1 && menu2 == 1){
100;
} else {
0;
};
*Martin
Copy link to clipboard
Copied
First of all, you should start using semicolons 😉
Did I get you right, that there a two conditions to trigger opatity: menu1 AND menu2 must be selected?
Then you have to write it this way:
if (menu1 == 1 && menu2 == 1){
100;
} else {
0;
};
*Martin
Copy link to clipboard
Copied
that's greate. i found 2 answers with yours, and both works perfect.
Copy link to clipboard
Copied
Yep Martin said it, you can only return 1 value so you have to combine the if/else statements. Here's a reference on more comparison synatx:
https://www.w3schools.com/js/js_comparisons.asp
Copy link to clipboard
Copied
If I understand you correctly and both menu's are on a controller layer then you need an if (condition a = 1 && condition b = 1) then, else statement. If that is correct then the cleanest way to write the expression looks like this:
ctrl = thisComp.layer("Controller");
testA = ctrl.effect("Menu 1")("Menu");
testB = ctrl.effect("Menu 2")("Menu");
if (testA==1 && testB == 1)
0
else
100
Copy link to clipboard
Copied
Sorry Rick, but that's what I posted 3 hours ago and you miss the curly brackets (Expressions might don't need them, but a clean java script code does).
*Martin
Copy link to clipboard
Copied
thank you all guys for help. i solved my problem with your help. this is a great place for me.
Copy link to clipboard
Copied
Also note that the ? operator is a good solution for these kinds of if statements that just create a single value. It has the form
CONDITION ? IF_VALUE : ELSE_VALUE
if (menu1 == 1 && menu2 == 1){
100;
} else {
0;
};
is the same as
(menu1 == 1 && menu2 == 1) ? 100:0;
It also has the advantage that it can be used in variable declarations.
var result = (menu1 == 1 && menu 2 == 1) ? 100:0;
which is not possible with if statements.
Copy link to clipboard
Copied
There are many ways to skin a cat in Javascript. One of which is this:
var value1 = comp("kj v1").layer("controller").effect("kac tl")("Menu").value;
var value2 = comp("kj v1").layer("controller").effect("kacinci soru")("Menu").value;
var result = (value1 && value2) * 100;
result;
The logic behind (value1 && value2) * 100 is as follows;
Not saying you have to use such logic, as it might look unfamiliar and weird for beginners but just letting you know that such a thing exists. The more you know, the less you know.
Copy link to clipboard
Copied
Yes, if your goal is to write hard to read code, Tomas example can be optimized even further to
var result = Math.min(menu1,menu2) * 100;
or
var result = menu1 * menu2 * 100;
😄
But good code should be easy to read, so I recommend
var result = (menu1 == 1 && menu 2 == 1) ? 100:0;
because it litterally says "Is menu1 equal to 1 and menu2 equal to 1? If so, take 100 otherwise 0".
Copy link to clipboard
Copied
... and if you want to be as compact as possible you can also skip the == 1 checks:
var result = (menu1 && menu2) ? 100:0;
Copy link to clipboard
Copied
now, i am using this script
var menu1 = comp("kj v1").layer("controller").effect("yanlis cevap")("Menu")
var menu2 = comp("kj v1").layer("controller").effect("dogru cevap")("Menu")
if(menu1 != 1&&menu2 == 2)100; else 0
this works fine. I want to add something new. Once this script has started, one of the layers should be hidden in frame 50th and after in the timeline. it should only be visible before the 50th frame. I tried something but failed.
Copy link to clipboard
Copied
hideAt = 50 * thisComp.frameDuration;
if (time >= hideAt){
0;
} else {
100;
};
The other guys will show you another thousend ways how to write an if-condition 😉
*Marin
Copy link to clipboard
Copied
is this a good way to combine both scripts
var menu1 = comp("kj v1").layer("controller").effect("joker")("Menu")
hideAt = 150 * thisComp.frameDuration;
if(menu1 == 2&&time >= hideAt)0; else 100