ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

compare current time with the nearest marker time expression issue.

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Michael Song
compare current time with the nearest marker time expression issue.
on Jun 6, 2017 at 8:50:07 am

Hi all,

I want to move a text layer above for a fixed amount of pixels when it hits the marker.
I write this expression in the Position property of the text layer
if ( time == thisComp.marker.nearestKey(time).time ) {
value+=[0,40];}

But After Effects always shows an expression error for it.
What's the problem with this expression?
Thanks!


Return to posts index

Chris Scalzo
Re: compare current time with the nearest marker time expression issue.
on Jun 6, 2017 at 2:11:53 pm

did you want it to move if it is greater than that time or exactly at that time? (note, it might not be exactly at that time on any frame)


Return to posts index

Michael Song
Re: compare current time with the nearest marker time expression issue.
on Jun 6, 2017 at 2:20:13 pm

exactly at that time


Return to posts index


Chris Scalzo
Re: compare current time with the nearest marker time expression issue.
on Jun 6, 2017 at 2:28:39 pm

Maybe something like this would work for you. (sorry working on 3 others things and no time to test.

if ( time.value.toFixed(3) == thisComp.marker.nearestKey(time).time ) {
value+=[0,40];}


Return to posts index

Chris Scalzo
Re: compare current time with the nearest marker time expression issue.
on Jun 6, 2017 at 2:30:37 pm

I forgot to round both numbers off.. try this.

if ( time.value.toFixed(3) == thisComp.marker.nearestKey(time).time.toFixed(3) ) {
value+=[0,40];}


Return to posts index

Michael Song
Re: compare current time with the nearest marker time expression issue.
on Jun 6, 2017 at 2:37:51 pm

Thanks. So I guess what's wrong with my original expression is that it compares two values that are not of the same type. So they can not be compared until they are turned into the same type. Is this correct?


Return to posts index


Chris Scalzo
Re: compare current time with the nearest marker time expression issue.
on Jun 6, 2017 at 3:11:54 pm

I assumed the rounding error would increase the likelihood that you wouldn't hit that exact time ever.

eg. if you set keyframe at 10s the value of "time" wouldn't be exactly 10.

try creating a text layer and in the text source at the expressions"time". go to 10 seconds and you will see what I mean. Plus your expression wouldn't add that value permanently to the value. just when it hit that time exactly and would change back. if you count the markers with some type of nummarkers expression you could add the to the value when greater than nearest marker your amount you wanted to add times the number of markers you passed.

If I am incorrect, someone please correct me.


Return to posts index

Michael Song
Re: compare current time with the nearest marker time expression issue.
on Jun 7, 2017 at 12:44:15 am

if ( time.value.toFixed(3) == thisComp.marker.nearestKey(time).time.toFixed(3) ) {
value+=[0,40];}

AE still shows as error. Any idea?


Return to posts index

Santi Agustí
Re: compare current time with the nearest marker time expression issue.
on Jun 7, 2017 at 3:20:31 am

I think this answer may lead you to a solution: https://forums.creativecow.net/thread/227/30151
(and the easeFrames is pretty cool, so you can have a smooth transition, or just change that value with 0 for a jump)

just change the last line of Philip Neve's code to make it work on Y, so it can be:


offsetAmt = 40;
easeFrames = 10;
n = 0;
if (marker.numKeys > 0){
n = marker.nearestKey(time).index;
if (marker.key(n).time > time) n--;
}
yOffset = 0;
if (n > 0){
t = time - marker.key(n).time;
yOffset = easeOut(t,0,framesToTime(easeFrames),(n-1)*offsetAmt,n*offsetAmt);
}
[value[0],value[1] + yOffset];




Return to posts index


Michael Song
Re: compare current time with the nearest marker time expression issue.
on Jun 7, 2017 at 4:01:39 am

I think I might find out the issue.
The Position property expects an array(if you don't split it). So the IF condition in expression has to have an array return value if the condition isn't fulfilled.

if ( time.toFixed(3) == thisComp.marker.nearestKey(time).time.toFixed(3) ) {
value+=[0,40];}else{value;}


Also you don't need time.value to work. time.toFixed(3) works just by itself.


Return to posts index

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