Log in

View Full Version : Possible to apply conditional to a block of code?


wrybread
3rd March 2011, 13:14
I'm guessing there must be a better way to do conditionals in AVISynth than the way I'm doing it.

Here's what I'm doing:

color = true
a = (color == true) ? a.RGBAdjust(2, 1, 1) : a

That just seems so obtuse. And furthermore I can't apply it to a block of code. So I'm guessing I'm missing something?

Any tips on simply doing something like:

color = true
if (color == true)
{
a = a.RGBAdjust(2, 1, 1)
b = b.RGBAdjust(2, 1, 1)
}

Motenai Yoda
3rd March 2011, 15:05
function Block_Of_Code(clip c){
bla bla bla
return return_clip
}

a=true

f= (a) ? last.Block_Of_Code() : last

um3k
3rd March 2011, 18:12
You could also check out Gavino's GScript: http://forum.doom9.org/showthread.php?t=147846

Gavino
3rd March 2011, 18:22
Turning a block of code into a function is a useful tip, but is not always possible. The original example needs to update two clips but a function can only return one value.

The conventional approach here would be simply to write:
a = (color == true) ? a.RGBAdjust(2, 1, 1) : a
b = (color == true) ? b.RGBAdjust(2, 1, 1) : b

This can get tedious and ugly if you need even more assignments subject to the same condition.
A more user-friendly alternative (especially for complex code) is to use GScript.