Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression error – can’t find out what’s wrong with my syntax

  • Expression error – can’t find out what’s wrong with my syntax

    Posted by Jarle Leirpoll on May 10, 2019 at 5:37 pm

    Expressions question:

    I’ve opened an old project in AE 16.1.1, and I get some expressions errors (as expected). I’ve fixed most of them, but five remain, and I don’t understand how I can fix them.

    Here’s one of the expressions, and the error message. The syntax is very similar on the other four.

    This code triggers an error on line 6: index 3 out of range for stream of dimension 1

    txt = thisComp.layer("Source").text.sourceText;
    i = Math.floor((txt.length-1)/2);
    j = (txt.length%2) ? i : i+1;
    n = -1;
    while (i >= 0 && j < txt.length){
    if (txt[i] == " "){
    n = i;
    break;
    }else if (txt[j] == " "){
    n = j;
    break;
    }
    i--;
    j++;
    }
    if (n < 0) txt; else txt.substr(0,n)

    Jarle Leirpoll
    PremierePro.net

    Jarle Leirpoll replied 6 years, 12 months ago 2 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    May 10, 2019 at 6:03 pm

    Change the first line to:

    txt = thisComp.layer(“Source”).text.sourceText.value;

    Dan

  • Jarle Leirpoll

    May 10, 2019 at 7:10 pm

    Perfect! Works like a charm. I’m not surprised, though. ☺
    Thanks Dan!

    Whenever you have the time, I’d like to understand why it’s now important to add “.value”

    Jarle Leirpoll
    PremierePro.net

  • Dan Ebberts

    May 10, 2019 at 7:18 pm

    My guess is that sourceText is an object, not the actual text array–the legacy engine lets you get away with indexing it as an array but the new engine is more strict.

    Dan

  • Jarle Leirpoll

    May 10, 2019 at 7:22 pm

    Ah, that makes sense. Thanks Dan!

    Jarle Leirpoll
    PremierePro.net

  • Jarle Leirpoll

    May 12, 2019 at 9:29 am

    Almost there! I’ve managed to split the text between words, and to adjust the split point with a slider. Works great, but the layer that grabs the second line starts with a space, not with a letter.

    How can I strip away the space at the start?

    Here’s the code for this layer.

    txt = thisComp.layer("Source").text.sourceText.value;
    nWords = Math.round(thisComp.layer("Controls").effect("Word Split")("Slider"));
    if (nWords > 0){
    count = 0;
    for (i = 0; i < txt.length; i++){
    if (txt[i] == " "){
    count++;
    if (count == nWords) break;
    }
    }
    if (count < nWords) txt
    else txt.substr(i,txt.length)
    }else{
    i = Math.floor(txt.length-1);
    n = -1;
    while (i >= 0){
    if (txt[i] == " "){
    n = i;
    break;
    }
    i--;
    j++;
    }
    if (n < 0) ""
    else txt.substr(n+1)
    }

    Jarle Leirpoll
    PremierePro.net

  • Jarle Leirpoll

    May 13, 2019 at 8:47 am

    SOLVED!

    I got help from Jonathan Beresford in a Facebook group. He suggested to use trim(), and that worked.
    Here’s the final code. Hope it can help someone else.

    txt = comp("Subtitles 25 fps 1080x1920 With Line Break").layer("Source").text.sourceText.value;
    nWords = Math.round(comp("Subtitles 25 fps 1080x1920 With Line Break").layer("Controls").effect("Word Split")("Slider"));
    if (nWords > 0){
    count = 0;
    for (i = 0; i < txt.length; i++){
    if (txt[i] == " "){
    count++;
    if (count == nWords) break;
    }
    }
    if (count < nWords) txt
    else txt.substr(i,txt.length).trimLeft()
    }else{
    i = Math.floor(txt.length-1);
    n = -1;
    while (i >= 0){
    if (txt[i] == " "){
    n = i;
    break;
    }
    i--;
    }
    if (n < 0) ""
    else txt.substr(n+1)
    }

    Jarle Leirpoll
    PremierePro.net

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