Skip to main content
GregL2570
Participating Frequently
April 21, 2022
Answered

Help with Expression for Adding a Prefix Number to a Slider Control Range Attached to Source Text

  • April 21, 2022
  • 2 replies
  • 1836 views

I'm trying to animate a 7 digit number counting up sequentially from 1000000 to 1987654 and am using an expression control slider attached to a Source Text element. The problem I'm trying to solve is that the "edit range" values on the slider control max out at the starting point value (1000000), so I'm trying to figure out how to add an expression that can place a prefix of "1" at the begining of the number sequence and use the slider control to count up using only a 6-digit range instead. (i.e. 100000 to 987654). Can anyone help with how to use an expression to add that single digit "1" at the begining of the Source Text element or slider control?

This topic has been closed for replies.
Correct answer Dan Ebberts

You could set keyframes on your slider for 0 and 987654 and then use a source text exrpession like this:

1000000 + Math.round(effect("Slider Control")("Slider"))

 

2 replies

Mylenium
Legend
April 21, 2022

You have 32000 discrete values on a slider and that's it. A direct approach will never work therefore. Even if you were to hard-code the leading 1 into the string, you still don't have enough numbers to count up to your value. therefore the motto of the day has to be to actually scale the values, i.e. multiply decimal values with a fixed number. Going from 1000000 to 9999999 therefore could be as trivial as slider*1000 and setting the start and end values to 1000 and 9999.9999, respectively.

 

Mylenium

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
April 21, 2022

You could set keyframes on your slider for 0 and 987654 and then use a source text exrpession like this:

1000000 + Math.round(effect("Slider Control")("Slider"))

 

GregL2570
GregL2570Author
Participating Frequently
April 21, 2022

Thanks. I am already using the round expression to remove the decimal points, but the problem I'm trying to solve it that the slider control range maxes out at my starting point (.i.e 1000000) and I need to count up from there to 1987654. The only way that I can do that, is to set a 6-digit range and (hopefully) just hard code a prefix "1" at the begining that always remains static in order to end up with a 7-digit sequence. I'm looking for how to write an expression that adds a single digit "1" at the start of the source text.

Dan Ebberts
Community Expert
Community Expert
April 21, 2022

This would be another way:

n = Math.round(effect("Slider Control")("Slider"));
"1" + String(n).padStart(6,0);