Forums › Adobe After Effects Expressions › valueAtTime() on a REGEX Text Layer
-
valueAtTime() on a REGEX Text Layer
-
David Avila
January 9, 2022 at 8:02 amHi,
I know that valueAtTime only works on Properties, but I was wondering if there was a way to use Dan Ebbert’s timeRemap expression to trigger animations using a TextLayer which has undergone REGEX editing?
The idea is that the Text Layer in question is ‘1’ only a few frames (it gets checked each frame).
... var P2Output = P2Str.replace(Px_ValueExp , '').split(',')[0]; // Regex + Split. Will change from 0 to 1. // Original Script by Dan Ebberts | Apply to timeRemap txt = P2Output; t = 0; f = timeToFrames(time); if (txt == 1) { t = time; while (f >= 0) { if (txt.valueAtTime(framesToTime(f)) == 0) // the line that returns an error { t = time - framesToTime(f); break; } f--; } } t
Normally this returns an error as the text-layer changes to a String. I was wondering, if we knew that P2Output will equal to 1 for only a few frames, could we trigger a layer's animation while P2Output = 1?
-
Dan Ebberts
January 9, 2022 at 6:10 pmIt’s not clear to me exactly what you’re trying to do, but if variable txt is a string, it seems like you should either use parseInt(txt,10) to convert it to a number, or change your conditional tests to look for characters (“0” or “1”) rather than numbers (0 or 1) .
Dan
-
David Avila
January 9, 2022 at 6:21 pmWell, valueAtTime() doesn’t work with strings or ints. IIRC, it has to be done on a property. My initial text layer is a whole paragraph which I truncate using REGEX — once I do that, valueAtTime() doesn’t work on the reference anymore.
I’m trying to initialize a pre-comp’s animation whenever this text layer is ‘`1’, otherwise, freeze the pre-comp at 0:00. I believe in order to do this, valueAtTime() is necessary for the while-loop to work.
-
Andrei Popa
January 9, 2022 at 8:06 pmI think that on the error line, you use .valueAtTime() on a string. I think you should use .valueAtTime() first, then apply the regex+split. So get the sourceText property first, apply .valueaAtTime, then apply your replace(or any function that you want to apply to the string)
-
David Avila
January 10, 2022 at 7:11 pmThe two master-variables are being calculated every frame, so I was wondering how I would re-write the script to use them somehow. I just need for the comp’s timeRemap to jump and play from 0:00 while the value is true…Something like this:
Edit, I figured it out but I was wondering if someone could please break down the way the while-loop works. A friend and I were talking about it and it’s kinda confusing, thank you.
The expression:
var masterEval = thisComp.layer("MasterEvalFunction").text.sourceText; var masterResult = masterEval.includes("P2_Being_Hit: 1"); // Original Script by Dan Ebberts txt = masterEval; t = 0; f = timeToFrames(time); if ( masterResult ) { t = time; while (f >= 0) { if ( !txt.valueAtTime(framesToTime(f) ).includes("P2_Being_Hit: 1") ) { t = time - framesToTime(f); break; } f--; } } t
-
Dan Ebberts
January 10, 2022 at 8:51 pmThe while loop just starts at the current frame, and goes back in time, frame by frame, until it finds the most recent frame where the text included the target phrase. It then sets variable t to how long ago that occurred.
-
David Avila
January 10, 2022 at 9:12 pmI see!
A friend reduced the expression down quite a bit:
time - (function(f){ while(f-- >= 0) if(!thisComp.layer("MasterEvalFunction").text.sourceText.valueAtTime(framesToTime(f+1)).includes("P2_Being_Hit: 1")) return framesToTime(f+1); })(timeToFrames(time))
-
David Avila
July 25, 2022 at 5:53 pmSorry for the thread bump, but I was wondering if it’s possible to have the nested composition’s time jump to 0 instead of the main-comp’s current time.
var t = 0;
var f = timeToFrames(time);
t = time;
while (f >= 0)
{
if ( checker() == 0 )
{
t = time - framesToTime(f);
break;
}
else
{
f--;
}
}
t
I’d like to get something like if t > 0, timeRemap = 0, + 1 frame every time it meets the condition. I think it requires another while loop, but I’m not sure how to ‘store’ values.
Currently, t can be anywhere, 100f – 110f; 505-515, etc. The nested composition’s animation is at 0f- 10f.
Log in to reply.