Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Change slider value ratio to percentage

  • Change slider value ratio to percentage

    Posted by Ludovic Chan on October 4, 2023 at 1:57 am

    Hi,

    I’m trying to change the ratio value of my slider to make it as percentage.

    Let me explain :

    In my example, I have this text “This is a test” which is displayed word by word, one word at a time. So : “This” then “is” then “a” then “test”.

    This text has a Source Text expression which is doing the word by word animation and is linked to a slider that can control which word is displayed, so 1=This / 2=is / 3=a / 4=test.

    I have 2 keyframes to display the entire sentence over time : 1 to 4.

    What I would like to do is being able to use the slider as a percentage while keeping the same function. Meaning that instead of my 2 keyframes 0 to 4, I would just put 1 to 100 (in this case 1=This / 100=test).

    Is this even possible ? Thank you for your time, would really appreciate your help.

    The expression I’m using for the word by word animation is this one :

    t = value.split(” “);
    i = Math.floor(effect(“Word”)(“Slider”))-1;
    if (i<0) i = 0;
    if (i>=t.length) i = t.length-1;
    t[i];

    Ludovic Chan replied 2 years, 7 months ago 3 Members · 5 Replies
  • 5 Replies
  • Julian Chojnacki

    October 4, 2023 at 3:28 am

    Hi Ludovic,

    you can do it like this:

    const t = value.split(" ");

    const i = Math.floor(effect("Word")("Slider").value * (t.length - 1) / 100);

    t[i];

  • Ludovic Chan

    October 4, 2023 at 9:57 am

    Hi Julian,

    Thank you so much it works!! Would you mind explaining it to me ? Or just ignore this else 🙂

    Have a great day!

  • Brie Clayton

    October 4, 2023 at 2:03 pm

    Thanks for this solve, Julian!

  • Julian Chojnacki

    October 4, 2023 at 3:42 pm

    Sure, here’s a breakdown:

    1. The first line takes your text value and splits it into an array of words based on the empty space ” ” between them.
    2. The second line converts the slider value from a 0 – 100 range into the word index based on the length of our word array. Since arrays are 0-based, we subtract 1 from it so we start counting from the first word. We then round the result down to the nearest integer using Math.floor, so we only deal with whole numbers.
    3. Finally, we use the calculated word index from “const i” to determine which word of our word array “const t” should be outputted.

    In your original code, you had some fallbacks to ensure your slider would only output a range from 0 – wordCount-1. If you plan to use your slider strictly from 0 – 100, we don’t need to modify them and can simply get rid of them.

    Last thing I did was to declare the variables with “const”. It’s not necessary in AE, but a common practice in JavaScript 🙂

  • Ludovic Chan

    October 5, 2023 at 8:45 am

    Thank you I appreciate it, it’s clearer now!

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