Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions increment text layer

  • increment text layer

    Posted by Nick Leigh on November 30, 2010 at 8:16 pm

    Ok I give up. I have been search the forum and expression examples for a couple hours now and can’t figure out how to increment a text layer when certain conditions are met.

    I have markers set on a null layer that tells me at what time goals were scored in a hockey game. So I want to increment up by one when I hit a marker when time = the marker time and the marker comment = 3. I have seen though debugging that I am getting inside the condition statement to increment up but for some reason it isn’t working. This expression is in the text layer I am trying to increment.

    I posted the expression I have so far with no luck.

    Thanks for any help.

    Nick

    if (time > 0)
    {
    curScore = parseInt(thisComp.layer("Away Score").text.sourceText);
    c = thisComp.layer("Game Markers");
    n = c.marker.nearestKey(time).index;

    if (c.marker.key(n).time == time && c.marker.key(n).comment == 3)
    {
    home = curScore + 1;
    }
    else
    {
    home = curScore;
    }
    //home = 'key:'+n+', cur:'+time+', keytime:'+c.marker.key(n).time+', comment:'+c.marker.key(n).comment+',score:'+
    }
    else
    {
    home = 0;
    }

    home;

    Dan Ebberts replied 4 years, 4 months ago 4 Members · 9 Replies
  • 9 Replies
  • Nick Leigh

    November 30, 2010 at 8:30 pm

    I decided to do this a different way just counting the markers that met the conditions.

    if (time > 0)
    {
    count = 0;
    c = thisComp.layer("Game Markers");
    n = c.marker.nearestKey(time).index;
    if (c.marker.key(n).time > time) n--;

    // loop thru
    for (i = n; i > 0; i--)
    {
    if (c.marker.key(i).comment == 3)
    {
    count++;
    }
    }
    }
    else
    {
    count = 0;
    }

    away = count;

    But would still like to know how to increment if it is at all possible.

  • Dan Ebberts

    November 30, 2010 at 8:31 pm

    Here’s the basic idea:


    c = thisComp.layer("Game Markers");
    count = 0;
    for (i = 1; i <= c.marker.numKeys; i++){
    if (c.marker.key(i).time > time) break;
    if (c.marker.key(i).comment == "3") count++;
    }
    count

    Dan

  • Dan Ebberts

    November 30, 2010 at 10:15 pm

    I think I know what you’re getting at, but you can’t do it that way. Expressions have no memory and have no access to values they calculated on previous frames. So you can’t just increment a previous value, you have to recalculate it first.

    Dan

  • Navarro Parker

    June 13, 2013 at 8:56 pm

    I’m having trouble getting this to work.

    My layer markers are on the same text layer as the expression. But the starting number isn’t incrementing when it hits a marker.

    c = thisLayer;
    count = 10;
    for (i = 1; i <= c.marker.numKeys; i++){
    if (c.marker.key(i).time > time) break;
    if (c.marker.key(i).comment == "3") count++;
    }
    count

  • Dan Ebberts

    June 13, 2013 at 9:02 pm

    It only counts markers that have a comment of “3” (without the quotes). Did you want it to count all the markers? You could do that this way:

    c = thisLayer;
    count = 10;
    for (i = 1; i <= c.marker.numKeys; i++){
    if (c.marker.key(i).time > time) break;
    count++;
    }
    count

    Although, if that’s what you want, you could just get the index of the most recent, previous marker and add that to count.

    Dan

  • Navarro Parker

    June 13, 2013 at 9:12 pm

    Sure… why not use the index! 🙂

  • Navarro Parker

    June 13, 2013 at 9:41 pm

    And how about decrementing by -1?

  • Thomas Hannen

    April 4, 2022 at 10:12 am

    How would I do this as one marker per word instead of per character? Many thanks

  • Dan Ebberts

    April 4, 2022 at 1:31 pm

    I’m having trouble figuring out where words vs. characters factors into this. Can you provide more info?

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