Our website is made possible by displaying online advertisements to our visitors. Consider supporting us by disable your adblocker or Try ConvertXtoDVD and convert all your movies to DVD. Free trial ! :)

Avisynth - How to define default values for function parameters?

1. I know Avisynth function parameters can have default values. For instance, the Subtitle filter can be used in the short form

Subtitle(clip,"text")

without giving any additional arguments (x, y...) because they already have default values.

But I do not know how to define default values for my own functions. I have read the guides, searched the Web, etc. but couldn't find anything that works for me.

As an example, say we have the following simple function, which adds or subtracts 2 numbers, depending on the conditional parameter Plus.

Function PlusMinus(int n1, int n2, bool Plus)
{
result = (Plus==True) ? n1+n2 : n1-n2
return result
}

How do we define "Plus" to be True as default?

So that we can use
n3 = PlusMinus(n1, n2)

as the short form of
n3 = PlusMinus(n1, n2, True)  Quote
2.  Quote
3. Plus = default(Plus, true)
Thank you.

Do you mean coding the function like this?

Function PlusMinus(int n1, int n2, bool Plus)
{
Plus = default(Plus, true)

result = (Plus==True) ? n1+n2 : n1-n2
return result
}

Because it isn't working

AviSource("J:\01.avi").Trim (525, PlusMinus(525, 100, True)) gives no error

AviSource("J:\01.avi").Trim (525, PlusMinus(525, 100)) gives "Invalid arguments to function PlusMinus"  Quote
4. I have found this work

Function PlusMinus(int n1, int n2, bool "Plus")
{

Plus = default(Plus, true)

result = (Plus==True) ? n1+n2 : n1-n2
return result
}

ie, defining the parameter as bool "Plus", instead of just bool Plus

The quotation marks did the trick here.  Quote
5. Yes, the argument needs to be in quotes for default() to work.  Quote
6. AviSource("J:\01.avi").Trim (525, PlusMinus(525, 100)) gives "Invalid arguments to function PlusMinus"
This will work:
AviSource("J:\01.avi").Trim (525, PlusMinus(n1 = 525, n2 = 100))
If you omit one or more arguments you have to use named parameters.  Quote

Statistics