0

I'm trying to create a counter that automatically updates to the next value once per second. I have that part figured out:

string = "7609,7758,7916,8063,8217,8382,8545,8701,8871,9049,9241,9386,9533,9722,9911,10055,10196,10321,10327,10451,10646,10854,11005,11195,11411,11583,11740,11904,12051,12177,12308,12404,12484,12558,12637,12725,12805,12882,12982,13088,13212,13340,13486,13674,13840,";
array = string.split(",")
l=array.length;

sek = Math.floor(time);

if(sek<l){
            array[sek]; 
}else{
            "End of Data";
}

However, now I'm trying to animate it. I've made simple counters that count from a starting number to a final number using Slider Control and keyframes, but is there a way to automate it? The final project is going to have multiple counters going at the same time, with around 750 points of data in total, so automating would save so much time.

  • It's a little bit unclear what you're asking. When you say "is there a way to automate it", what exactly are you wanting to automate? BTW you could just do array = [7609,7758,7916,8063,8217,8382, … without making it into a string and then splitting it. – stib Apr 8 at 14:00
  • To clarify, what I have currently updates the count once per second. What I'd like it to do is to animate the numbers in between 7609 and 7758 and then between 7758 and 7916 rather than just going straight from 7609 to 7758. Rephrased: I'd like to see the integer values in between 7609 and 7758 like 7609 then 7610 then 7611, all the way up to 7758. What I've done in the past is link 2 numbers via the Slide Control and setting keyframes. This counts up like I want it to, however I have to manually set every single keyframe and type in the 2 numbers I want it to start and finish with. – izaic3 Apr 8 at 18:35
  • With regards to the array, would this be what you mean? array = [7609,7758,7916,8063,8217,8382,8545,8701,8871,9049,9241,9386,9533,9722,9911,10055,10196,10321,10327,10451,10646,10854,11005,11195,11411,11583,11740,11904,12051,12177,12308,12404,12484,12558,12637,12725,12805,12882,12982,13088,13212,13340,13486,13674,13840] l=array.length; sek = Math.floor(time); if(sek<l){ array[sek]; }else{ "End of Data"; } – izaic3 Apr 8 at 18:36
  • When you get from 7609 to 7758, what happens then? Do you want it to continue to count until it gets to 13840? Maybe explain what you are trying to do, big picture. – stib Apr 9 at 1:13
0

This will animate between the values in the array, hitting each value precisely at the second mark though the viewer won't be able to notice because the numbers will be moving too fast.

var dataArr = [7609,7758,7916,8063,8217,8382,8545,8701,8871,9049,9241,9386,9533,9722,9911,10055,10196,10321,10327,10451,10646,10854,11005,11195,11411,11583,11740,11904,12051,12177,12308,12404,12484,12558,12637,12725,12805,12882,12982,13088,13212,13340,13486,13674,13840]; 
var sek = Math.floor(time);
if (sek < dataArr.length - 1){
   Math.floor(linear(time-sek, dataArr[sek], dataArr[sek+1]));
} else {
    "out of data";
}

For bonus points you can add commas or culture-appropriate separators by replacing the line that starts with Math.floor(linear … with:

Math.floor(linear(time-sek, dataArr[sek], dataArr[sek+1])).toLocaleString("en-AU");

where you replace "en-AU" with your locale, e.g. for Chinese Decimal units use "zh-Hans-CN-u-nu-hanidec" and it will look like: 七,六〇九

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.