Skip to main content
keesm30622030
New Participant
September 30, 2019
Question

Counting numbers via expression with non-animated text.

  • September 30, 2019
  • 2 replies
  • 497 views

Hi all,

 

I am trying to make a counting number in my animation where the final number has to read "1.287 comments".

At the moment I am using FluxVFX's expression:

 

start=parseInt(thisLayer.text.sourceText="0");
end=parseInt(text.sourceText);
val=Math.round(easeOut(time, 1.5, 2.5,start, end));
s=""+ val;
if (s.length > 3){
s.substr(0, s.length -3) + "." + s.substr(-3);
}else{
s
}
 
What do I need to add for it to place "comments" behind my number?
Normally I would place it in a seperate text layer behind it, but then it doesn't move, since it's left alligned.
 
Thanks in advance!
 
Regards,
Kees
 
    This topic has been closed for replies.

    2 replies

    Community Expert
    September 30, 2019

    Do you want the line of text to move as the last two numbers increase? If that is it and you want to type in the line of text add this line to the end of Dan's expression:

    prefix + outStr + decimals + " " +(value)

    If you want to add the text to the expression change the last line to this:

    prefix + outStr + decimals + " This is my text"

     One caution. Unless you use a monospaced font the text is going to jump around a lot as the numbers animate on because 1 is narrower than a 0. It's going to look bad. 

     

    If you are stuck with a standard font then you'll have to come up with an expression that counts the number of digits the counter is generating, assigns the average spacing for each digit, then adjusts the position of the supplemental text. I can't do that one without experimentation. Personally, I would just set up the counter, then add a second layer and animate position. Don't make this too hard.

    keesm30622030
    New Participant
    October 1, 2019
    Hi rick, thanks for your explanation. This worked perfectly for me! especially the part for the easy fix 🙂
    Community Expert
    September 30, 2019

    I would just take a look at Universal counter - Dan Ebberts's. If you read the article and use his counter, you can add your extra text right inside the expression. If you modify the last section of the expression you can also include text entered manually and put it before or after the counter.

     

    Another option is to use sourceRectAtTime() to control the position of a second text layer that has been parented to your counter. 

     

    Without seeing a screenshot showing exactly what you want to achieve and a little more detailed description it is pretty hard for me to give you a complete solution.

    keesm30622030
    New Participant
    September 30, 2019

    Hi Rick_Gerard,

     

    Thanks alot for your reply!


    I don't have alot of experience with expressions and I couldn't find out which part of the code would let me add text.

    Would you mind clarifying where I could type the text that will come after the counter?

     

    Enclosed you'll find a screenshot of what I have now, the bottom 2 numbers should have text behind them in the end.

     

    I don't know how else I can clarify more what I am trying to achieve.