Page 1 of 1

Expression to toggle opacity every nth frame

PostPosted: Wed Dec 08, 2021 11:02 pm
by thefisher86
I have spent wayy too long trying to figure out the answer myself and I've gotten nowhere. I've been trying to better understand how the Simple Expression scripting works but have not been able to find a ton of resources outside the Scripting Guide for Fusion 8.

All I want to do is programmatically toggle back and forth between 2 clips based on the current frame. So V2 has opacity=1 for 10 frames, then the opacity moves to 0 for 10 frames so V1 is showing underneath. I know I can do this by cutting the clip myself but I need to do this often and across 20+ minutes of footage so manually would take forever.

So far I've figured out that I can get the current frame with
Code: Select all
time
but I can't seem to figure out how to set a variable in a simple expression within an if/then statement. Here's the pseudo-code for what I want to do:
Code: Select all
myFramesVar = 25;
myOpacityVar = 1;

If (time - myFramesVar < 0){
   myFramesVar = myFramesVar+ 25;
   If (myOpacityVar = 1){
      myOpacityVar = 0;
      Else{myOpacityVar = 1;
}

So a couple things about my pseudo-code. I'm pretty sure this IS NOT the proper formatting to be using in Resolve/LUA. However I'm new to LUA and Resolve so I'm pretty sure I just need to know how to "say" this in the right formatting.

If the above code doesn't work what I'm really doing is asking "If the current frame - 25 is < 0 then add 25 to myFramesVar and toggle the Opacity to 0 if it's currrently 1 or 1 if it's currently 0.

Expectation is that every 25 frames the opacity toggles itself and now I have a reusable method to strobe a clip above another.

Thank you for any help anyone can provide.

Re: Expression to toggle opacity every nth frame

PostPosted: Thu Dec 09, 2021 4:38 am
by xunile
This is the code I used for a 30 fps timeline to toggle every 30 frames between two tracks. I used a Dissolve node and used it for the expression of the Background/Foreground parameter.

Code: Select all
iif(time % 60 < 30,0,1)