PDA

View Full Version : function woes, conditional operations and default()


mf
8th May 2003, 18:22
My function:
function mfToon(clip orig, int "ssw", int "ssh") {
ssw2 = orig.width * ssw
ssh2 = orig.height * ssh
some.filters()
BicubicResize(ssw2, ssh2, 0, 0.75)
some.more.filters()
}

If I set:
Default(ssw, 4)
Default(ssh, 4)
and use mfToon() without arguments, I get: "Evaluate: operands of `*' must be numeric".
If I use mfToon(ssw=4, ssh=4) then it works. So I must be doing something wrong with default(). So I try something else.

If I set:
Defined(ssw) ? nop() : ssw = 4
Defined(ssh) ? nop() : ssh = 4
instead, I get "left operand of `=' needs to be a variable". To my knowledge ssw IS a variable, and if it isn't, it should be defined, right?

What am I doing wrong?

HomiE FR
8th May 2003, 20:38
Hi, you should just write :

ssw = Default(ssw, 4)
ssh = Default(ssh, 4)

(it works here, so I hope it'll work for you too)

PS : thanks for mfToon, I'm trying it right now ! :)

mf
8th May 2003, 21:09
WAI~ WAI~~ That works! Arigatou-yo~~~~~~

mf
8th May 2003, 22:04
Ok. Now another thing I don't get.

I now have this:
function mfToon(clip orig, int "ssw", int "ssh", int "xstren", int "xthresh", \
int "cwarp", bool "sharpen") {
sharpen = Default(sharpen, true)

And then this:
sharpen ? return final : return dark
}
I get "Script error: expected: `:'". This time though, I really need this conditional expression thing to work.

Guest
8th May 2003, 22:45
How about:

return sharpen ? final : dark

HomiE FR
8th May 2003, 22:45
I think you should assign something to something else in your conditional expression.

Like this, it should work I think :

output = (string(sharpen) == "true") ? final : dark
return output

(I use the string(...) because I once had problems with sharpen == true)

But I guess that this is also correct :
output = sharpen ? final : dark
return output

Bye

Edit : too late (and what wrote neuron2 is shorter too)

mf
9th May 2003, 12:00
Originally posted by neuron2
How about:

return sharpen ? final : dark
Whack the author of the AVISynth manual on the head for not supplying any examples. :D Thanks :). I even had a C programmer over but he didn't understand it. :rolleyes:

WarpEnterprises
9th May 2003, 13:30
outch, don't want to get whacked, so where could I add something?

That a function has to have a "return"?

Wilbert
9th May 2003, 13:42
Whack the author of the AVISynth manual on the head for not supplying any examples.
Maybe I'm misunderstanding you, but vdub_filters.avs contains a bunch of similar examples.

Guest
9th May 2003, 13:49
And it's called a conditional *expression* for a reason! 'return' is not an expression. :)

mf
9th May 2003, 14:05
Originally posted by Wilbert
Maybe I'm misunderstanding you, but vdub_filters.avs contains a bunch of similar examples.
Well I've looked at those, but frankly they weren't very clear on the real syntax. (And to be even more honest, the writing style was even inconsistent :D) A nice example to add would be:

function question(clip c, bool yesno) {
text = yesno ? "yes" : "no"
return c.Subtitle(text)
}

Or something. At least for me that would make things a LOT clearer. No offence about the whack btw :).

Wilbert
9th May 2003, 14:21
I will add that example to the docs. Thanks.