Quantcast Avisynth: Conditional User Defined Functions? - digitalFAQ.com Forums [Archives]
  #1  
03-31-2004, 07:12 AM
Prodater64 Prodater64 is offline
Free Member
 
Join Date: Mar 2003
Location: Palma de Mallorca - España
Posts: 2,925
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Reply With Quote
Someday, 12:01 PM
admin's Avatar
Site Staff / Ad Manager
 
Join Date: Dec 2002
Posts: 42
Thanks: ∞
Thanked 42 Times in 42 Posts
  #2  
03-31-2004, 07:22 AM
Dialhot Dialhot is offline
Free Member
 
Join Date: May 2003
Posts: 10,463
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Reply With Quote
  #3  
03-31-2004, 11:11 AM
kwag kwag is offline
Free Member
 
Join Date: Apr 2002
Location: Puerto Rico, USA
Posts: 13,537
Thanks: 0
Thanked 0 Times in 0 Posts
Maybe what you want is something like this

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

-kwag
Reply With Quote
  #4  
03-31-2004, 12:22 PM
incredible incredible is offline
Free Member
 
Join Date: May 2003
Location: Germany
Posts: 3,189
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to incredible
And if the "then" way will "do nothing" I remember still this was

x==y ? c=userdefined1() : NOP
Reply With Quote
  #5  
03-31-2004, 12:35 PM
Dialhot Dialhot is offline
Free Member
 
Join Date: May 2003
Posts: 10,463
Thanks: 0
Thanked 0 Times in 0 Posts
Let's go for an other wzy to do all that :

Code:
(x==y) ? userdefined1() : userdefined2()
c=last
Do you need more ?
Reply With Quote
  #6  
03-31-2004, 12:57 PM
kwag kwag is offline
Free Member
 
Join Date: Apr 2002
Location: Puerto Rico, USA
Posts: 13,537
Thanks: 0
Thanked 0 Times in 0 Posts
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

-kwag
Reply With Quote
  #7  
03-31-2004, 02:44 PM
Prodater64 Prodater64 is offline
Free Member
 
Join Date: Mar 2003
Location: Palma de Mallorca - España
Posts: 2,925
Thanks: 0
Thanked 0 Times in 0 Posts
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?
Reply With Quote
  #8  
03-31-2004, 03:15 PM
kwag kwag is offline
Free Member
 
Join Date: Apr 2002
Location: Puerto Rico, USA
Posts: 13,537
Thanks: 0
Thanked 0 Times in 0 Posts
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
Reply With Quote
  #9  
03-31-2004, 03:39 PM
Prodater64 Prodater64 is offline
Free Member
 
Join Date: Mar 2003
Location: Palma de Mallorca - España
Posts: 2,925
Thanks: 0
Thanked 0 Times in 0 Posts
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!!!)
Reply With Quote
  #10  
03-31-2004, 03:48 PM
kwag kwag is offline
Free Member
 
Join Date: Apr 2002
Location: Puerto Rico, USA
Posts: 13,537
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Prodater64
Ohh!, I understand, thank you, Kwag.
And thanks to all.
Just in case:
== (comparison) is not the same as = (assignment)

-kwag
Reply With Quote
  #11  
03-31-2004, 03:52 PM
Prodater64 Prodater64 is offline
Free Member
 
Join Date: Mar 2003
Location: Palma de Mallorca - España
Posts: 2,925
Thanks: 0
Thanked 0 Times in 0 Posts
Sorry, I had edit my previous post and you don't saw the last question.
Reply With Quote
  #12  
03-31-2004, 04:21 PM
Dialhot Dialhot is offline
Free Member
 
Join Date: May 2003
Posts: 10,463
Thanks: 0
Thanked 0 Times in 0 Posts
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 !)
but it will work only if avisynth grammar accepts non constant lvalues with ":" operator

Avisynth is not C language.
Reply With Quote
  #13  
03-31-2004, 11:38 PM
Peter1234 Peter1234 is offline
Free Member
 
Join Date: Feb 2003
Posts: 237
Thanks: 0
Thanked 0 Times in 0 Posts
removed stupid question
Reply With Quote
Reply




Similar Threads
Thread Thread Starter Forum Replies Last Post
Avisynth: Can you give optimal scripts functions explanations ??? le_barbu Avisynth Scripting 7 10-16-2006 07:20 AM
Avisynth: Stuck with new script functions Blubear Avisynth Scripting 3 05-01-2006 08:08 AM
Avisynth: Conditional Variables? Prodater64 Avisynth Scripting 3 03-27-2004 11:25 PM
Avisynth: Question on conditional operator kwag Avisynth Scripting 16 06-18-2003 10:29 PM
DVDToolbox 0.12.1 all functions jorel Video Encoding and Conversion 1 03-31-2003 11:21 AM

Thread Tools



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