Skip to main content
FirstGuy
Participant
October 27, 2021
Question

Weird problam with expressions on source text

  • October 27, 2021
  • 2 replies
  • 449 views

Came across this problem

 

I'm trying to animate a text layer, that will go from 0 to 1 (and have at least 0.1, 0.2, 0.3 etc... while going there) via slider, and an expression that uses that slider, and will constantly have the letter "M" by its right side. so it'll be 0M, 0.1M, 0.2M and so on...

I've tried many many expressions, but none of them - NONE OF THEM, will have M by the right side of the number while the number a decimal... 

 

const sliderValue = effect('Slider Control')('Slider');
const isWholeNumber = sliderValue % 1 === 0

const parsedNumber = isWholeNumber ? Math.trunc(sliderValue) : sliderValue;

`${ parsedNumber }M`;

--------------------------------

`${ slider1 }${ +slider2 === 0 ? '' : ('.' + slider2) }M`

--------------------------------

`${ slider1 }${ +slider2 === 0 ? '' : ('.' + slider2) }` + ' M'

none of these will work as the M disappears once there's a decimal. 

BUT........ for some reason... it DOES WORK - with OTHER letters: like R, Y, Z... but it doesn't work with M. doesn't work with N either...

 

unfortunately I need it to work with M so I won't have to make a specific layer for M. 

Why wouldn't this work? anyone?

 

Thanks. 

This topic has been closed for replies.

2 replies

Mylenium
Legend
October 28, 2021

If it was converted from PS, chances are that this is a Unicode/ OpenType issue and the character encoding is different because it's not the default Latin/ western range. Or to put it simpler: The "M" could be from another language subset and messes up things.

 

Mylenium

FirstGuy
FirstGuyAuthor
Participant
October 28, 2021

Well that could explain it. thank you! 🙂

Mylenium
Legend
October 27, 2021

You're making things way too complicated. AE can handle all of this just fine without the extra icing. AE's expression engine really works best when you just let it do its thing and don't go fancy with literals, exact type matching or weird constructors. It really could be as simple as using code that would have worked ten years ago:

 

mSlider=thisComp.layer("XYZ").effect("Slider")("Slider").value;

if (mSlider != 0)

  {mOut=mSlider.toFixed(2)}

else

  {mOut =0.00}

 

mOut.toString()+" M"

 

Mylenium

 

FirstGuy
FirstGuyAuthor
Participant
October 28, 2021

Well thank you first of all, but the problem isn't the complication of the code, either way your code fails too, as the letter M disappears when the number has decimals.  see attached

 

 

Tomas B. aka Tom10
Inspiring
October 28, 2021

I just checked and expression from Mylenium works 100%. 
Make sure:

1. On your layer, you don't have any Text Animation effects applied, which might trim characters - thats why they could disappear without you noticing.
2. Try to create a new comp, and recreate the same effect.

It has to be some leftovers around the corner 🙂