Answers.Body: <p>To shorten what you've already written you could pack all the open mouth values into an array and then find if the x value is in it:</p>
  
  <pre><code>var scaleYVals = [1 , 3, 7, 10, 11];
  (scaleYVals.indexOf(x) &gt; -1)? [148,199] : [148, 189];
  </code></pre>
  
  <p>The second line uses the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator" rel="nofollow noreferrer">ternary</a> form of <code>if (foo){bar} else {baz}</code>, which can be written as <code>(foo)? bar : baz</code>. <a href="https://www.w3schools.com/jsref/jsref_indexof_array.asp" rel="nofollow noreferrer"><code>IndexOf</code></a> returns the index of an element of an array, so if the value of x (bad name for a variable except if you're referring to an x coordinate, BTW) is 7 then <code>indexOf</code> will return <code>2</code>. If the value is not in the array it returns <code>-1</code></p>
  
  <p>The problem with looking at the previous mouth shape is that you could still end up with no movement: say there was a sequence: open, open, closed. If you disable the stretching on the second open mouth you'll have the sequence stetched, unstretched, unstretched. It also greatly complicates the expression.</p>
  
  <p>How about you make it so that the stretch happens at the beginning of the open mouth and then goes back briefly before the next phoneme? </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-07T12:32:15.427Z
Answers.LastActivityDate: 2019-02-07T12:32:15.427Z
Answers.UserDisplayName: stib
Body: <p>I want to make a Dorkly animation (<div class="youtube-embed"><div>
                  <iframe width="640px" height="395px" src="https://www.youtube.com/embed/ZVTLsQ8iNCM?start=0"></iframe>
              </div></div>), that is, 8-bit puppets opening and closing their mouths. The difference I want to add is when the mouth is open the puppet get stretched (scaled) in the Y axis and when is closed the puppet returns to its original size. I have managed to get an automatic sync method so the problem now lies with the scale thing.</p>
  
  <p>I've assigned a null that responds to the values adopted by the mouth so I ordered it when the mouth is open, stretch the puppet. To do this, I've used the following expression:</p>
  
  <pre><code>x=thisComp.layer("SIDE MOUTH GREEN").effect("LJ - visemes - MSD")("viseme nr.")
  if(x==1)[148,199];
  else if (x==3) [148,199];
  else if (x==7) [148,199];
  else if (x==10) [148,199];
  else if (x==11) [148,199];
  else [148,189];
  </code></pre>
  
  <p>The problem is as follows. When there are two consecutive sounds that are equivalent to an open mouth (FOR - GO - tten), the puppet doesn't move and that's a pretty dull stuff. What should be said to AF is: if after an open mouth value goes another open mouth value, on the changed value disable the stretching for X time. What'd be the expression that would be needed to achieve that? </p>
  
  <p>I know I could do it manually but I want to broaden my skills.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-07T23:45:57.410Z
Comments.Text: Just a tip, try out the new(ish) character animator if you haven't already! I haven't, but it is built for this kind of thing.
Comments.UserDisplayName: Spencer
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-07T23:47:46.500Z
Comments.Text: Also, could you just use the puppet tool and rig up some bones with DUIK? Does that achieve the look you're after? Then you shouldn't need expressions but can work with parenting (assuming I understand the question)
Comments.UserDisplayName: Spencer
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-08T23:59:29.637Z
Comments.Text: First of all I wanted to share something I forgot to write in my previous message. Lars is a genius (https://vimeo.com/220359572) and has made an expression that allows the transfer of keyframes from CA (Character Animator) to AF and it works perfectly well. It saves you a lot of time. So, Spencer, I already have CA in my pocket ;P.
Comments.UserDisplayName: Ángel Molina López
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-08T23:59:29.637Z
Comments.Text: Stib, thanks for shortening it. I know little of expressions and my knowledge is based on what people post and my ability to understand and test what they post. Sorry for the mistakes I've made haha. (I've just put the expression and After Effects says "scaleYvals.IndexOf is not a function") Regarding the problem, what I wanted was to disable the stretching for a moment (for example 3-4 frames) and then enable it again. But, obviously, your solution is more logical because the shrinking should take place BEFORE the next open phoneme xd. In other words, it would look something like this:
Comments.UserDisplayName: Ángel Molina López
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-08T23:59:29.637Z
Comments.Text: The mouth opens and the puppet stretches. The next keyframe with an open phoneme is getting closer so the puppet shrinks. The keyframe has been reached and the puppet stretches again. As you have already said, this will be terribly difficult to set up, but as it is an action that is going to happen frequently, I wanted to automate it as much as possible. If you think it's too complicated and it's not worth making something up, it'll be done manually and we'll call it a day.
Comments.UserDisplayName: Ángel Molina López
Tags: <after-effects><after-effects-expressions>
Title: Modify the scale depending on the order of the keyframe values
UserDisplayName: Ángel Molina López
ThreadText: # Modify the scale depending on the order of the keyframe values
  
  (Asked by: username_0 on 2019-02-06)
  
  I want to make a Dorkly animation (
  
  ), that is, 8-bit puppets opening and closing their mouths. The difference I want to add is when the mouth is open the puppet get stretched (scaled) in the Y axis and when is closed the puppet returns to its original size. I have managed to get an automatic sync method so the problem now lies with the scale thing.
  
  I've assigned a null that responds to the values adopted by the mouth so I ordered it when the mouth is open, stretch the puppet. To do this, I've used the following expression:
  
  ```
  x=thisComp.layer("SIDE MOUTH GREEN").effect("LJ - visemes - MSD")("viseme nr.")
  if(x==1)[148,199];
  else if (x==3) [148,199];
  else if (x==7) [148,199];
  else if (x==10) [148,199];
  else if (x==11) [148,199];
  else [148,189];
  
  ```
  
  The problem is as follows. When there are two consecutive sounds that are equivalent to an open mouth (FOR - GO - tten), the puppet doesn't move and that's a pretty dull stuff. What should be said to AF is: if after an open mouth value goes another open mouth value, on the changed value disable the stretching for X time. What'd be the expression that would be needed to achieve that?
  
  I know I could do it manually but I want to broaden my skills.
  
  **Tags:** after-effects, after-effects-expressions
  
  > **Comments:**
  > **username_1**: Just a tip, try out the new(ish) character animator if you haven't already! I haven't, but it is built for this kind of thing.  
  > **username_1**: Also, could you just use the puppet tool and rig up some bones with DUIK? Does that achieve the look you're after? Then you shouldn't need expressions but can work with parenting (assuming I understand the question)  
  > **username_0**: First of all I wanted to share something I forgot to write in my previous message. Lars is a genius (https://vimeo.com/220359572) and has made an expression that allows the transfer of keyframes from CA (Character Animator) to AF and it works perfectly well. It saves you a lot of time. So, username_1, I already have CA in my pocket ;P.  
  > **username_0**: username_2, thanks for shortening it. I know little of expressions and my knowledge is based on what people post and my ability to understand and test what they post. Sorry for the mistakes I've made haha. (I've just put the expression and After Effects says "scaleYvals.IndexOf is not a function") Regarding the problem, what I wanted was to disable the stretching for a moment (for example 3-4 frames) and then enable it again. But, obviously, your solution is more logical because the shrinking should take place BEFORE the next open phoneme xd. In other words, it would look something like this:  
  > **username_0**: The mouth opens and the puppet stretches. The next keyframe with an open phoneme is getting closer so the puppet shrinks. The keyframe has been reached and the puppet stretches again. As you have already said, this will be terribly difficult to set up, but as it is an action that is going to happen frequently, I wanted to automate it as much as possible. If you think it's too complicated and it's not worth making something up, it'll be done manually and we'll call it a day.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-02-07. Score: 0
  
  To shorten what you've already written you could pack all the open mouth values into an array and then find if the x value is in it:
  
  ```
  var scaleYVals = [1 , 3, 7, 10, 11];
  (scaleYVals.indexOf(x) > -1)? [148,199] : [148, 189];
  
  ```
  
  The second line uses the [ternary](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator) form of `if (foo){bar} else {baz}`, which can be written as `(foo)? bar : baz`. [`IndexOf`](https://www.w3schools.com/jsref/jsref_indexof_array.asp) returns the index of an element of an array, so if the value of x (bad name for a variable except if you're referring to an x coordinate, BTW) is 7 then `indexOf` will return `2`. If the value is not in the array it returns `-1`
  
  The problem with looking at the previous mouth shape is that you could still end up with no movement: say there was a sequence: open, open, closed. If you disable the stretching on the second open mouth you'll have the sequence stetched, unstretched, unstretched. It also greatly complicates the expression.
  
  How about you make it so that the stretch happens at the beginning of the open mouth and then goes back briefly before the next phoneme?
  
  
  ---
  
  