VideoHelp Forum
+ Reply to Thread
Results 1 to 6 of 6
Thread
  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 Quote  
  2. Originally Posted by Zeppo View Post
    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 Quote  
  3. 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 Quote  
  4. Yes, the argument needs to be in quotes for default() to work.
    Quote Quote  
  5. Originally Posted by CoralMan View Post
    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 Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!