Answers.Body: <p>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:</p>
  <blockquote>
  <p>If the percents checkbox is ticked then you're set to 100 otherwise
  you're 0, Okthxbye.<br />
  Oh, did I mention also if the background checkbox is ticked
  then you're set to 100 otherwise you're 0.</p>
  </blockquote>
  <p>What happens if percents is ticked but background isn't?</p>
  <p>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 <em>percents</em> is ticked <strong>or</strong> <em>background</em> is ticked then <em>100</em>, otherwise <em>0</em>. The javascript way of writing this is to use the logical <strong>or</strong> operator: <code>||</code></p>
  <pre class="lang-js prettyprint-override"><code>let percents = thisComp.layer(&quot;Controller &quot;).effect(&quot;Checkbox percents&quot;)(&quot;Checkbox&quot;);
  let bg = thisComp.layer(&quot;Controller &quot;).effect(&quot;Checkbox background &quot;);
  if (percents &gt; 0 || bg &gt; 0) { 100 } else {0}
  </code></pre>
  <p>the two <code>let</code> statements just assign variables to the checkbox values, to keep the logic bit tidy, otherwise it looks like</p>
  <pre class="lang-js prettyprint-override"><code>if(thisComp.layer(&quot;Controller &quot;).effect(&quot;Checkbox percents&quot;)(&quot;Checkbox&quot;)&gt;0 || thisComp.layer(&quot;Controller &quot;).effect(&quot;Checkbox background &quot;)(&quot;Checkbox&quot;)&gt;0) {100} else {0};
  </code></pre>
  <p>Which is a bit hard to read. You could also shorten the last line by omitting the <code>&gt; 0</code> bit. If something is equal to 0, javascript treats it as <code>false</code> and anything &gt; 0 is automatically truth`. So the last line could be simply:</p>
  <pre class="lang-js prettyprint-override"><code>if (percents || bg) { 100 } else {0}
  </code></pre>
  <p>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 <em>percents</em> is checked <strong>and</strong> <em>background</em> is checked. The javascript notation for a logical <strong>and</strong> is <code>&amp;&amp;</code>. So now your expression would look like</p>
  <pre class="lang-js prettyprint-override"><code>let percents = thisComp.layer(&quot;Controller &quot;).effect(&quot;Checkbox percents&quot;)(&quot;Checkbox&quot;);
  let bg = thisComp.layer(&quot;Controller &quot;).effect(&quot;Checkbox background &quot;);
  if (percents &amp;&amp; bg) { 100 } else {0}
  </code></pre>
  <p>Boolean logic can be more complex, you can use <strong>not</strong> (or in JS notation <code>!</code>) to return <code>true</code> when something is <code>false</code>, e.g. <code>!(1 == 1)</code> returns <code>false</code>, and you can group things together using brackets to make more complex expressions. E.g.:</p>
  <pre class="lang-js prettyprint-override"><code>if ((! percents) &amp;&amp; background){100} else {0}
  </code></pre>
  <p>returns 100 only if percents is <strong>not</strong> checked <strong>and</strong> background is checked. Boolean logic can be represented by Truth tables, like this:</p>
  <p><a href="https://i.sstatic.net/ZEP6u.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ZEP6u.png" alt="enter image description here" /></a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-03T00:30:45.600Z
Answers.LastActivityDate: 2022-03-01T22:38:24.523Z
Answers.LastEditDate: 2022-03-01T22:38:24.523Z
Answers.UserDisplayName: stib
Body: <p>I have a checkbox for background and its items. , write the script</p>
  <pre class="lang-js prettyprint-override"><code>if(thisComp.layer(&quot;Controller &quot;).effect(&quot;Checkbox background &quot;)(&quot;Checkbox&quot;)&gt;0) {100} else {0};
  </code></pre>
  <p>it is working</p>
  <p>But when checkbox for another one of the items above that background write the script</p>
  <pre class="lang-js prettyprint-override"><code>if(thisComp.layer(&quot;Controller &quot;).effect(&quot;Checkbox percents&quot;)(&quot;Checkbox&quot;)&gt;0) {100} else {0}; 
  if(thisComp.layer(&quot;Controller &quot;).effect(&quot;Checkbox background &quot;)(&quot;Checkbox&quot;)&gt;0) {100} else {0};
  </code></pre>
  <p>but not working</p>
  <p><a href="https://i.sstatic.net/pmgs0.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/pmgs0.png" alt="enter image description here" /></a></p>
  
Tags: <after-effects><after-effects-expressions>
Title: how to Checkbox Control one item twice in after effect?
UserDisplayName: joud desing
ThreadText: # how to Checkbox Control one item twice in after effect?
  
  (Asked by: username_0 on 2021-01-28)
  
  I have a checkbox for background and its items. , write the script
  
  ```js
  if(thisComp.layer("Controller ").effect("Checkbox background ")("Checkbox")>0) {100} else {0};
  
  ```
  
  it is working
  
  But when checkbox for another one of the items above that background write the script
  
  ```js
  if(thisComp.layer("Controller ").effect("Checkbox percents")("Checkbox")>0) {100} else {0}; 
  if(thisComp.layer("Controller ").effect("Checkbox background ")("Checkbox")>0) {100} else {0};
  
  ```
  
  but not working
  
  [![enter image description here](https://i.sstatic.net/pmgs0.png)](https://i.sstatic.net/pmgs0.png)
  
  **Tags:** after-effects, after-effects-expressions
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-02-03. Score: 1
  
  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: `||`
  
  ```js
  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
  
  ```js
  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:
  
  ```js
  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
  
  ```js
  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.:
  
  ```js
  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:
  
  [![enter image description here](https://i.sstatic.net/ZEP6u.png)](https://i.sstatic.net/ZEP6u.png)
  
  
  ---
  
  