Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Random but predefined increments for counter

  • Random but predefined increments for counter

    Posted by Marko Novkov on January 29, 2021 at 8:53 am

    Hello,

    I am trying to have my counter grow only by predefined increments (10, 50, 100, 250).
    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.
    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. It is okay if the expression rounds up close to the value of my keyframe (I’ll have a HOLD keyframe sometimes)

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

    (Source: His Highness Laurence at notbyhalf.com. Thank you )

    // 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”);

    // 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 ?

    Dan Ebberts replied 5 years, 3 months ago 2 Members · 1 Reply
  • 1 Reply
  • Dan Ebberts

    January 29, 2021 at 9:52 pm

    I think you might have better luck if you describe in more detail what the desired result would look like–when values change, how much they change, etc. It’s hard to get much useful info from the expression you posted…

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