fvisagie
29th November 2012, 21:18
Hi All,
I'm putting together a script where the main decision variable ends up as an integer [0..n] as below. It sounds natural to use this integer with Select() to call the corresponding filter. However, when I do this, it seems ALL items in the Select() list have their validation code invoked, not just the one you want to call. I actually discovered this with real filters, but the same happens with functions here.
# "Received" parameter
Filter = "f0"
# Evaluate 'Filter'
filtnum = (Filter == "f0") ? 0 : \
(Filter == "f1") ? 1 : \
(Filter == "f2") ? 2 : 3
Assert(filtnum < 3, """'Filter' choice """" + Filter + """" is invalid""")
# Filter defaults: filter0 filter1 filter3
rad = Select( filtnum, 24, 24, 12 )
str = Select( filtnum, 10.0, 10.0, 5.0 )
thrL = Select( filtnum, 0, 0, 2 )
thrH = Select( filtnum, 0, 0, 40 )
# This works
(filtnum == 0) ? Version.filter0(rad, str) : \
(filtnum == 1) ? Version.filter1(rad, str) : \
(filtnum == 2) ? Version.filter2(rad, str, thrL, thrH) : \
Assert(false, "This shouldn't happen")
# This fails with "filter2: radius must be < 16", although filter2() should never be invoked
Select(filtnum, \
Version.filter0(rad, str), \
Version.filter1(rad, str), \
Version.filter2(rad, str, thrL, thrH) \
)
function filter0 (clip c, int radius, float strength) {
Assert(radius < 32, "filter0: radius must be < 32")
return(MessageClip("0"))
}
function filter1 (clip c, int radius, float strength) {
Assert(radius < 32, "filter1: radius must be < 32")
return(MessageClip("1"))
}
function filter2 (clip c, int radius, float strength, int thrL, int thrH) {
Assert(radius < 16, "filter2: radius must be < 16")
return(MessageClip("2"))
}
Why is this?
Other than using other conditional constructs, or splitting variables so each function/filter has its own set which I would regard very messy, what other ways are there of getting around this issue?
Many thanks,
Francois
I'm putting together a script where the main decision variable ends up as an integer [0..n] as below. It sounds natural to use this integer with Select() to call the corresponding filter. However, when I do this, it seems ALL items in the Select() list have their validation code invoked, not just the one you want to call. I actually discovered this with real filters, but the same happens with functions here.
# "Received" parameter
Filter = "f0"
# Evaluate 'Filter'
filtnum = (Filter == "f0") ? 0 : \
(Filter == "f1") ? 1 : \
(Filter == "f2") ? 2 : 3
Assert(filtnum < 3, """'Filter' choice """" + Filter + """" is invalid""")
# Filter defaults: filter0 filter1 filter3
rad = Select( filtnum, 24, 24, 12 )
str = Select( filtnum, 10.0, 10.0, 5.0 )
thrL = Select( filtnum, 0, 0, 2 )
thrH = Select( filtnum, 0, 0, 40 )
# This works
(filtnum == 0) ? Version.filter0(rad, str) : \
(filtnum == 1) ? Version.filter1(rad, str) : \
(filtnum == 2) ? Version.filter2(rad, str, thrL, thrH) : \
Assert(false, "This shouldn't happen")
# This fails with "filter2: radius must be < 16", although filter2() should never be invoked
Select(filtnum, \
Version.filter0(rad, str), \
Version.filter1(rad, str), \
Version.filter2(rad, str, thrL, thrH) \
)
function filter0 (clip c, int radius, float strength) {
Assert(radius < 32, "filter0: radius must be < 32")
return(MessageClip("0"))
}
function filter1 (clip c, int radius, float strength) {
Assert(radius < 32, "filter1: radius must be < 32")
return(MessageClip("1"))
}
function filter2 (clip c, int radius, float strength, int thrL, int thrH) {
Assert(radius < 16, "filter2: radius must be < 16")
return(MessageClip("2"))
}
Why is this?
Other than using other conditional constructs, or splitting variables so each function/filter has its own set which I would regard very messy, what other ways are there of getting around this issue?
Many thanks,
Francois