Expressions are evaluated until they return a value. Your first line will always return a value, and the expression will stop there. Think about what you're telling the property to do:
If the percents checkbox is ticked then you're set to 100 otherwise
you're 0, Okthxbye.
Oh, did I mention also if the background checkbox is ticked
then you're set to 100 otherwise you're 0.
What happens if percents is ticked but background isn't?
What you need to use is boolean logic. So if you want the opacity to be 100 if either checkbox is ticked you'd say: if percents is ticked or background is ticked then 100, otherwise 0. The javascript way of writing this is to use the logical or operator: ||
let percents = thisComp.layer("Controller ").effect("Checkbox percents")("Checkbox");
let bg = thisComp.layer("Controller ").effect("Checkbox background ");
if (percents > 0 || bg > 0) { 100 } else {0}
the two let
statements just assign variables to the checkbox values, to keep the logic bit tidy, otherwise it looks like
if(thisComp.layer("Controller ").effect("Checkbox percents")("Checkbox")>0 || thisComp.layer("Controller ").effect("Checkbox background ")("Checkbox")>0) {100} else {0};
Which is a bit hard to read. You could also shorten the last line by omitting the > 0
bit. If something is equal to 0, javascript treats it as false
and anything > 0 is automatically truth`. So the last line could be simply:
if (percents || bg) { 100 } else {0}
Now if you wanted the opacity to be 100 only if both the checkboxes were checked then you'd say: I want you to be 100 if percents is checked and background is checked. The javascript notation for a logical and is &&
. So now your expression would look like
let percents = thisComp.layer("Controller ").effect("Checkbox percents")("Checkbox");
let bg = thisComp.layer("Controller ").effect("Checkbox background ");
if (percents && bg) { 100 } else {0}
Boolean logic can be more complex, you can use not (or in JS notation !
) to return true
when something is false
, e.g. !(1 == 1)
returns false
, and you can group things together using brackets to make more complex expressions. E.g.:
if ((! percents) && background){100} else {0}
returns 100 only if percents is not checked and background is checked. Boolean logic can be represented by Truth tables, like this:
