Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › Count numbers up and down from array

  • Count numbers up and down from array

    Posted by Magdalena Broniecka on November 10, 2014 at 1:40 pm

    Hi,

    I’m working on a video that show info about amount of sale in malls in one country in 24 h. I need to show a different number for every hour. I wrote an expression but it only shows the last pass. As you can see, I have an array and I want the counter to grab 1st number and count to 2nd, grab 2nd and count to 3rd etc.
    I’ll be grateful for any ideas.

    Magda

    walmart = [ 498, 306, 68, 116, 130,146, 478, 1318,2328, 2904, 2818, 3246, 3536,3066,3030,2938,3342, 3222,3088,2730,2446,2792,2634,1838];
    for(i=0; i < 23; i++){
    startCount = walmart[i];
    endCount = walmart[i+1];
    countDur = 5;
    Math.round(linear(time,0,countDur,startCount,endCount))
    }

    Kevin Camp replied 11 years, 10 months ago 2 Members · 5 Replies
  • 5 Replies
  • Kevin Camp

    November 10, 2014 at 5:22 pm

    you’re pretty close… you just don’t need to use a loop, you just need to break your time into 5 second chunks, then interpolate between the values during each chunk…

    i think this should do what you need:

    walmart = [498, 306, 68, 116, 130,146, 478, 1318, 2328, 2904, 2818, 3246, 3536, 3066, 3030, 2938, 3342, 3222, 3088, 2730, 2446, 2792, 2634, 1838];

    countDur = 5;

    n = Math.floor(time/countDur);
    startCount = walmart[n];
    endCount = walmart[n+1];

    Math.round(linear(time%countDur, 0, countDur, startCount, endCount))

    Kevin Camp
    Art Director
    KCPQ, KZJO & KRCW

  • Magdalena Broniecka

    November 11, 2014 at 9:18 am

    Hi Kevin,

    Thank you for your answer. It works but not 100% correctly. There is no limit for n so when there are no more elements in array, it crashes. “Class ‘aray’ has no property or method named ’24’.

    Magda

  • Kevin Camp

    November 11, 2014 at 5:31 pm

    if your comp is longer than the value array then the expression will exceed the length of the array unless you prevent that from happening.

    there are a number of ways to do that, but clamp() might be the easiest.

    try changing this line:

    n = clamp(Math.floor(time/countDur), 0, walmart.length-1);

    Kevin Camp
    Art Director
    KCPQ, KZJO & KRCW

  • Magdalena Broniecka

    November 13, 2014 at 9:19 am

    I’m sorry, but there is another mistake. It crashes on 24 again, so I tried n = clamp(Math.floor(time/countDur), 0, walmart.length-2); and it loops between two last elements of the array. I can try with ending the comp before it crashes.

  • Kevin Camp

    November 13, 2014 at 8:56 pm

    sorry about that, i didn’t have after effects in front of me to test, and should have caught that anyway…

    you’ll need a if/else to catch it:

    walmart = [498, 306, 68, 116, 130,146, 478, 1318, 2328, 2904, 2818, 3246, 3536, 3066, 3030, 2938, 3342, 3222, 3088, 2730, 2446, 2792, 2634, 1838];
    countDur = 5;
    n = Math.floor(time/countDur);
    if (n

    Kevin Camp
    Art Director
    KCPQ, KZJO & KRCW

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy