- Posts: 5
- Joined: Tue Nov 13, 2018 5:33 am
- Real Name: Mark MacRae
It took me several hours to figure this little thing out on my own, and I couldn't find anybody doing exactly this so I figured I should post my code in case it is useful to anybody else.
It's still not perfect, but it works pretty good.
What I wanted was a countdown from 10 secs to 0 (the start time), then have it start counting up. I suppose to could have done this using a couple of different timers, but I wanted it all in one expression.
As someone with a coding background, I knew it would be easy to write and if-then-else type code snipet. Reading up LUA language got me most of the way there, but there is a key piece of info that most tutorials on expressions in DaVinci do not mention. Namely, if you want to write more than one line of code in your express, you must begin with a colon (:), then end each line with a semi-colon (;).
Anyway, here's the code for my expression:
It counts down from -10 to the word "START" at 0, then formats the seconds like a timer.
Here's a link to the video I used this element on:
(Sorry, this forum refuses to let me post the link no matter how I try, even though there is clearly a URL button here...)
You'll have to copy/paste the following after the / when you go to YouTube:
watch?v=mvxwoUMhAbM
The timer shows up soon after the intro.
In my example, my footage was 29.97 fps, you should substitute your own fps from you project settings. And the "-10" starts my timer at -10 secs instead of zero. Also, I didn't want the timer to run past about 53 seconds so I didn't bother actually coding it to display the minutes. You'll see the "00:" is just hard-coded.
I am posting this in the Fusion forum, but in fact I didn't use Fusion really, this is just a Text+ element in Resolve where I right-clicked the Styled Text and selected Expression.
Hopefully this helps somebody someday.
It's still not perfect, but it works pretty good.
What I wanted was a countdown from 10 secs to 0 (the start time), then have it start counting up. I suppose to could have done this using a couple of different timers, but I wanted it all in one expression.
As someone with a coding background, I knew it would be easy to write and if-then-else type code snipet. Reading up LUA language got me most of the way there, but there is a key piece of info that most tutorials on expressions in DaVinci do not mention. Namely, if you want to write more than one line of code in your express, you must begin with a colon (:), then end each line with a semi-colon (;).
Anyway, here's the code for my expression:
- Code: Select all
:t = math.floor(time/29.97-10); if t < 0 then return Text(string.format("%02d",t)); elseif t == 0 then return Text("START"); else return Text(string.format("00:%02d",t)); end
It counts down from -10 to the word "START" at 0, then formats the seconds like a timer.
Here's a link to the video I used this element on:
(Sorry, this forum refuses to let me post the link no matter how I try, even though there is clearly a URL button here...)
You'll have to copy/paste the following after the / when you go to YouTube:
watch?v=mvxwoUMhAbM
The timer shows up soon after the intro.
In my example, my footage was 29.97 fps, you should substitute your own fps from you project settings. And the "-10" starts my timer at -10 secs instead of zero. Also, I didn't want the timer to run past about 53 seconds so I didn't bother actually coding it to display the minutes. You'll see the "00:" is just hard-coded.
I am posting this in the Fusion forum, but in fact I didn't use Fusion really, this is just a Text+ element in Resolve where I right-clicked the Styled Text and selected Expression.
Hopefully this helps somebody someday.