digitalFAQ.com Forums [Archives]

digitalFAQ.com Forums [Archives] (http://www.digitalfaq.com/archives/)
-   Avisynth Scripting (http://www.digitalfaq.com/archives/avisynth/)
-   -   Avisynth: Conditional User Defined Functions? (http://www.digitalfaq.com/archives/avisynth/8891-avisynth-conditional-user.html)

Prodater64 03-31-2004 07:12 AM

Avisynth: Conditional User Defined Functions?
 
How can I execute conditional user defined functions like:

c = (x==y) ? userdefined1() : userdefined2()

where userdefined1 and userdefined2 results, are clips of not equal resolution.

Dialhot 03-31-2004 07:22 AM

The direct way :
Code:

u1=userdefined1()
u2=userdefined2()

c = (x==y) ? u1 : u2

The smart (and more efficient) way
Code:

u = (x==y) ? "userdefined1()" : "userdefined2()"
c = Eval(u)

Never used the second one but should work.

kwag 03-31-2004 11:11 AM

Maybe what you want is something like this :?:

x==y ? c=userdefined1() : c=userdefined2()

-kwag

incredible 03-31-2004 12:22 PM

And if the "then" way will "do nothing" I remember still this was

x==y ? c=userdefined1() : NOP

Dialhot 03-31-2004 12:35 PM

Let's go for an other wzy to do all that :

Code:

(x==y) ? userdefined1() : userdefined2()
c=last

Do you need more ? ;-)

kwag 03-31-2004 12:57 PM

Quote:

Originally Posted by Dialhot
Let's go for an other wzy to do all that :

Code:

(x==y) ? userdefined1() : userdefined2()
c=last

Do you need more ? ;-)

Why that one :?:
Either userdefined1() or userdefined2() will ALWAYS evaluate, so "c" will always have the value of the true or false condition.
So c=last is redundant, because it's already assigned once in either userdefined1() or in userdefined2() ;)
But then, we can get really obfuscated here, don't we :lol:

-kwag

Prodater64 03-31-2004 02:44 PM

Re: Conditional User Defined Functions
 
As I can see

Quote:

Originally Posted by Prodater64
How can I execute conditional user defined functions like:

c = (x==y) ? userdefined1() : userdefined2()

where userdefined1 and userdefined2 results, are clips of not equal resolution.

and

Quote:

Originally Posted by Dialhot
Code:

u1=userdefined1()
u2=userdefined2()

c = (x==y) ? u1 : u2


and

Quote:

Originally Posted by kwag
Maybe what you want is something like this :?:

x==y ? c=userdefined1() : c=userdefined2()

-kwag

are the same.

In Dialhot example, he asign the userdefined functions 1 an 2 to two variables and later (translation) wright the conditional statement same like mine one.
In Kwag example, he define his condition and later asign the results at c.
It is like say "If x = y, then c=udf1, if not c=udf2", and my way, "c=udf1 if x = y,c=udf2 if not". But what is the correct way? or all are the right ones?

kwag 03-31-2004 03:15 PM

Re: Conditional User Defined Functions
 
Quote:

Originally Posted by Prodater64

Quote:

Originally Posted by Dialhot
Code:

u1=userdefined1()
u2=userdefined2()

c = (x==y) ? u1 : u2


and

Quote:

Originally Posted by kwag
Maybe what you want is something like this :?:

x==y ? c=userdefined1() : c=userdefined2()

-kwag

are the same.

?

Nope. Not the same at all.

The statement:
c = (x==y) ? u1 : u2 assigns true or false ( 1 or 0 ) to c, depending on the value of x and y.

The statement:
x==y ? c=userdefined1() : c=userdefined2() assigns the correct value, depending on the condition that evaluates to true or false.

-kwag

Prodater64 03-31-2004 03:39 PM

Ohh!, I understand, thank you, Kwag.
And thanks to all.

Another question:

When I use the NOP statement, the script will continue beyond the conditional evaluation:
For example:

x==y ? c=userdefined1() : NOP
bicubicresize()...

In this case, resize will be applied whatever would be the condition?
(I hope you understand my english!!!)

kwag 03-31-2004 03:48 PM

Quote:

Originally Posted by Prodater64
Ohh!, I understand, thank you, Kwag.
And thanks to all.

Just in case:
:arrow: == (comparison) is not the same as :arrow: = (assignment) ;)

-kwag

Prodater64 03-31-2004 03:52 PM

Sorry, I had edit my previous post and you don't saw the last question.

Dialhot 03-31-2004 04:21 PM

Re: Conditional User Defined Functions
 
Quote:

Originally Posted by kwag
c = (x==y) ? u1 : u2 assigns true or false ( 1 or 0 ) to c, depending on the value of x and y.

Nope !

Actually this statement set c to u1 is the condition is true, u2 if not. And actually u1 is equal to the result of userdefined1 and u2 the result of userdefined2.

So that is EXACTLY what wee need to have.

Quote:

The statement:
x==y ? c=userdefined1() : c=userdefined2() assigns the correct value, depending on the condition that evaluates to true or false.
The only advantage of this uppon the previous is that you evaluate userdefine1 OR userdefine2, and not both ones.
So it's more efficient (as I told in my first post !)
:arrow: but it will work only if avisynth grammar accepts non constant lvalues with ":" operator :!:

Avisynth is not C language.

Peter1234 03-31-2004 11:38 PM

removed stupid question


All times are GMT -5. The time now is 10:34 PM  —  vBulletin © Jelsoft Enterprises Ltd

Site design, images and content © 2002-2024 The Digital FAQ, www.digitalFAQ.com
Forum Software by vBulletin · Copyright © 2024 Jelsoft Enterprises Ltd.