Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Random but predefined increments for counter

  • Random but predefined increments for counter

    Posted by Marko Novkov on January 28, 2021 at 3:53 pm

    Hello,

    I am trying to have my counter grow only by predefined increments (1, 5, 10, 25).
    I have linked it to my control slider and placed keyframes to which values it should go, but it is getting there 1 by 1.

    here is the expression I am currently using and trying to modify further:

    // Pick-whip number from Slider or Point Control and assign to mySlider

    // For example: var mySlider = effect(“Point Control”)(“Point”)[0];

    var mySlider = thisComp.layer(“CONTROL mn”).effect(“COUNTER”)(“Slider”)*10;

    // Use the commas function defined below to format your number.

    // Commas takes three properties – the number input,

    // the size of the groups of numbers and the number of decimal places.

    // You can use this function and only give it the base number.

    var numberstring = commas(mySlider);

    // This is the final output of this expression.

    // Use quotes around other text that you want to join with your numberstring variable.

    // eg. ‘$’ + numberstring + ‘ RAISED’

    ‘ ‘ + numberstring;

    function commas(number, groupSize, decimals){

    // Default settings if only a number is provided.

    groupSize = (groupSize == undefined) ? 3 : groupSize;

    decimals = (decimals == undefined) ? 0 : decimals;

    var theComma = ” “;

    // Round to given decimal places and convert number to string

    var strNumber = Number(number).toFixed(decimals).toString()

    // Store decimal places separately, with a bullet point if they exist or empty string if not.

    var arrNumber = strNumber.split(‘.’)

    var decimalPlaces = (arrNumber.length > 1) ? ‘.’ + arrNumber[1] : ”;

    // Convert to array to split into characters

    var anum = arrNumber[0].split(”);

    // New array to hold formatted number

    var fnum = new Array();

    var count = 0;

    // Process the characters in reverse, inserting a comma after each groupSize.

    for(var i = anum.length-1; i >= 0; i–){

    fnum.push(anum[i]);

    count++;

    // If the count is divisble by the groupSize and this is not the last (ie. first) character, add a comma.

    if(count % groupSize == 0 && i != 0){

    fnum.push(theComma);

    }

    }

    return fnum.reverse().join(”) + decimalPlaces;

    }

    Thank you so much for any help ♥

    Liran Tabib replied 5 years, 3 months ago 3 Members · 5 Replies
  • 5 Replies
  • Kevin Camp

    January 28, 2021 at 4:22 pm

    Are you using hold keyframes on your slider? AE will interpolate between keyframes unless you set the keyframes to hold. To do so, select all the keyframes and then right-click on one fo them and choose ‘Toggle Hold Keyframes’

  • Marko Novkov

    January 28, 2021 at 4:36 pm

    Thank you Kevin,

    I am not using the hold in this case since I need the counter to count many times until reaches the point where it should stop for a bit.
    For example: I need the counter to continue from 1250 until 4500 between the two slider keyframes, but the increments to be random from the predefined 5.

    Thank you so much !

  • Kevin Camp

    January 28, 2021 at 9:41 pm

    That will be a bit more difficult… I’m not sure how to get that to happen. I can make an array of the increment values and randomly grab a value from that array and add that to the counter as it counts, however if the random increment is 25 at one frame, then 1 on the next the frame the counter will actually decrease…

    you might ask on the expressions forum, there are definitely users over there that are better at expressions than I am.

  • Marko Novkov

    January 29, 2021 at 8:37 am

    Ah thank you so much, this already helps because I already thought I am on the expressions forum ?.

    Thank you! Have a good one

  • Liran Tabib

    January 29, 2021 at 9:52 am

    To create increments of a number you can add the expression:

    value-(value%5)// subtracts the remainder of five from the number

    It can be placed on a slider that drives the numbers or on the Number value of Counter Preset

    Cheers

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