Log in

View Full Version : Conditional execution in user-defined function


grannyGeek
23rd July 2007, 05:24
Please, could someone provide a simple example for making a function that can use a string or integer argument to call a filter setup out of a list of different presets. For example call ColorMill, and use numbers or names to call the different settings. (I get the settings from VDub vcf files.)

I want the equivalent of an If ... Then .... ElseIf .... Then.... ElseIf....EndIf statement. ( "Choose" would be even better, I never thought I would miss Visual Basic :) )
Then when I call the function in a script, have an argument that will use the settings Dark or Lite or Brite, etc.

If I only use two choices, the simple true/false example in Avisynth "Operators" documentation works for me, but I can't seem to make multiple conditions work.

Function CMill (clip input, string "pik")
{
klip = input
Lite = klip.Colormill(2500,2501,,,,,,etc)
Brite = klip.Colormill(2500,2506,,,,etc)
Dark = klip.Colormill(2500,2502,,,,,,,etc)
HiSat = klip.Colormill(2700, 2403,,,,,etc)

## here is where I would want an If---then---else list
# if PIK = "Lite" then klip = Lite
# if PIK = "Brite" then klip = Brite
# if PIK = "Dark" then klip = Dark
# if PIK = "Hisat" then klip = HiSat

Return klip
}

Would someone please explain to this dumb old granny how to do this? Many thanks in advance for any help.

Didée
23rd July 2007, 07:19
## here is an If---then---else list
klip = (PIK == "Lite") ? Lite :
\ (PIK == "Brite") ? Brite :
\ (PIK == "Dark") ? Dark :
\ (PIK == "Hisat") ? HiSat :
\ klip.Subtitle("Unknown preset in pik")

stickboy
23rd July 2007, 08:49
Please, could someone provide a simple example for making a function that can use a string or integer argument to call a filter setup out of a list of different presets.http://avisynth.org/oldwiki/index.php?page=Wrapper

grannyGeek
24th July 2007, 03:45
Didee, thank you so much for demonstrating the correct syntax.
I see now that my problem was in failing to call "klip" again at the end of the statement list; which was the equivalent of failing to add "End If" to If--Then statement.
This little failure taught me that I can write a function that is so borked that Avisynth won't operate anywhere until the avsi script is deleted from the plugins folder :D

Stickboy, I will find good uses for that script. The possibilities are endless! Many thanks.
And thank you for JDL_ApplyRange, I use it constantly for its ability to take named arguments.