FORUMS: list search recent posts

increment text layer

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Nick Leigh
increment text layer
on Nov 30, 2010 at 8:16:38 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;


Return to posts index

Nick Leigh
Re: increment text layer
on Nov 30, 2010 at 8:30:22 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.


Return to posts index

Dan Ebberts
Re: increment text layer
on Nov 30, 2010 at 10:15:05 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



Return to posts index



Dan Ebberts
Re: increment text layer
on Nov 30, 2010 at 8:31:44 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



Return to posts index

Navarro Parker
Re: increment text layer
on Jun 13, 2013 at 8:56:58 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




Return to posts index

Dan Ebberts
Re: increment text layer
on Jun 13, 2013 at 9:02:41 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



Return to posts index


Navarro Parker
Re: increment text layer
on Jun 13, 2013 at 9:12:53 pm

Sure... why not use the index! :)


Return to posts index

Navarro Parker
Re: increment text layer
on Jun 13, 2013 at 9:41:02 pm

And how about decrementing by -1?


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]