Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Line break expression is eating one character

  • Line break expression is eating one character

    Posted by David Cabestany on June 21, 2016 at 4:17 pm

    I’m using the expression below to generate random text and I need to break every 8 characters, which it does for the first line, but then every line after that breaks at 7.

    I tried changing the value to test the expression and the same happens, if I enter 10, the line breaks at 9 and so on.
    I changed the font to see if I need a mono spaced font and the same happened.

    My text box is more than enough to cover for the length of the lines.

    Can anyone tell me what’s going on?

    Thanks.
    D.

    rate=5;
    totalChar=64;
    lineBreak=10;
    posterizeTime(rate);
    selectionSet=["8","2","1","3","0","6"];
    txt="";
    for(i=0; i<totalChar; i++)
    {
    randomNumber=random(0,selectionSet.length);
    txt += selectionSet[Math.floor(randomNumber)];
    if (txt.length % lineBreak == 0) txt += "\r";
    }
    txt

    David Cabestany replied 10 years, 2 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    June 21, 2016 at 4:49 pm

    I think you just need to change the line break line to something like this:

    if (i > 0 && (i+1)%lineBreak == 0) txt += “\r”;

    Dan

  • David Cabestany

    June 21, 2016 at 4:55 pm

    Yes sir, that was it.

    Thanks!
    D.

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