David Avila
Forum Replies Created
-
Sorry 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.
-
I 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)) -
The 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
-
Well, 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.
-
I hope it’s not rude to tack on a question concerning the toComp function:
I’ve noticed that it requires two points. So when you want to use just one (x or y) point, you have to evaluate both, then pick one using the array syntax, right?
-
David Avila
June 9, 2021 at 6:43 pm in reply to: Text Layer to output a Layer’s Effects’ names and valuesI realized I could have just done this to create the 2 lists.
text = "";
for (i = 1; i < 50; i++) {
text +=
labelName${[i]} = thisComp.layer("Checker").effect(${[i]}).name;</p><p>labelValue${[i]} = thisComp.layer("Checker").effect(${[i]})("Checkbox");</p><p>}
text2 = "";
for( j = 1; j < 50; j++){
text2 +=
labelName${[j]} + ":" + "" + labelValue${[j]} + "\\r" +</p><p>}
text + "\r" + text2
-
Actually, the first one is what I wanted. I should have mentioned it, but it’s just going to be a simple animation like a strobe that blinks on and off while the text is “On”, and then resets or disappears when it’s “Off”.
In this new case, it holds it in its last position from before. I added an “else {n =0}” to your if-statement to reset it back to 0 so that it can replay once “On” comes up again.
This is my version of your first script with the attendant comments:
textResult = thisComp.layer("is_On_or_Off?").text.sourceText
thisLayerTimeRemap = 0; // thisLayer = Pre-composed layer whose animation starts at 0:00
if (textResult == "On"){
thisLayerTimeRemap = time; // sets pre-composed layer's time remap value equal to this composition's time value
playheadValue = timeToFrames(time); //this composition's playhead-value/time converted to frames
while (playheadValue >= 0){
if (textResult.valueAtTime(framesToTime(playheadValue)) == "Off"){ // checks if text-result says "Off"
thisLayerTimeRemap = time - framesToTime(playheadValue); // keeps its value at zero as time advances
break; // after setting the time-remap to 0, breaks out of the loop
}
playheadValue--; // subtracts 1 frame the playhead's time-value in order to move the animation forward by one frame.
}
}
thisLayerTimeRemap // outputs the result of this layer's Time Remap value
-
Thanks!
I applied the expression to a pre-compsed layer’s Time Remapping expression. My pre-composed layer’s animation begins at 0 and whenever my Text Layer reads “On”, it begins to play the animation as long as the Text Layer says “On”. When the Text Layer goes to “Off”, the Time Remapping value goes back to 0.
I believe I get most of it until the ‘break’ and the subtraction from ‘f’. Break terminates the while-loop after setting ‘t’ to 0 in the previous line? Subtracting one from ‘f’ is allowing the animation to increase by 1 frame at a time, right; it’s creating the 1 frame offset between the time remap’s value and the composition playhead value?
I don’t know if it’s uncouth to post my own renamed and commented version of your script on here?
-
Ahh, thanks.
I needed to also do it for a long else-if statement. I figured it was the same way, setting the style and the text result in each of the “else if” outputs.
-
speaking of font expressions, is there a way to have a text layer reference another layer, and have its own type of font-style-expression? like
thisComp.layer("Main").text.sourceText.style.setFauxBold(1).setFauxItalic(1).setFontSize(900)