Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 18th April 2019, 17:42   #1  |  Link
Dreamject
Registered User
 
Join Date: Dec 2018
Posts: 140
How to make check is variable defined?

I wanna import some core file, but I want to made core file selfish.

Like
if I import core file, coremode=0
if I load core file, coremode=1, so use variable in corefile.


How can I make this?
Dreamject is offline   Reply With Quote
Old 18th April 2019, 17:46   #2  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,364
http://avisynth.nl/index.php/Interna...efined#Defined
Wilbert is offline   Reply With Quote
Old 18th April 2019, 17:46   #3  |  Link
Dreamject
Registered User
 
Join Date: Dec 2018
Posts: 140
Thanks man
Dreamject is offline   Reply With Quote
Old 18th April 2019, 18:07   #4  |  Link
Dreamject
Registered User
 
Join Date: Dec 2018
Posts: 140

If I write

zet=9
what=Defined(zet)

I get what=true

If I write just

what=Defined(zet)

Potplayer says me "I do not know what 'zet' means"

Is that potplayer's error?
Dreamject is offline   Reply With Quote
Old 18th April 2019, 18:53   #5  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Same link as Wilbert posted.

Quote:
VarExist

VarExist(name) AVS+
Tests if the variable exists or not. Note: if variable exists, it returns true regardless of the "defined" state of the variab
Note

Quote:
Defined

Defined(var)
Tests if var is defined. Can be used inside Script_functions to test if an optional argument has been given an explicit value.
More formally, the function returns false if its argument (normally a function argument or variable) has the void ('undefined') type, otherwise it returns true.
Code:
blankClip

zet=9           # try Comment me out

what=VarExist("zet")

Subtitle(String(what))
EDIT:

Quote:
Is that potplayer's error?
PotPlayer just plays clip that Avisynth created.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 18th April 2019 at 18:56.
StainlessS is offline   Reply With Quote
Old 18th April 2019, 19:18   #6  |  Link
Dreamject
Registered User
 
Join Date: Dec 2018
Posts: 140
It's works, thanks, I didn't know I must use ""
Dreamject is offline   Reply With Quote
Old 18th April 2019, 19:35   #7  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
Originally Posted by Dreamject View Post
It's works, thanks, I didn't know I must use ""
I forgot to use Double quotes too when first testing that bit of script, it often happens to me so dont kick yourself too hard.

The Wiki dont define what it means by "var" or "name", perhaps it should.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 18th April 2019, 20:25   #8  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,823
You can do something like this for backwards compatibility, as only Avisynth+ has VarExist().

Try{ IsZet = defined(Zet) }
catch(err_msg){ IsZet = false }

or some other variation

Try{ Zet = Zet }
catch(err_msg){ Zet = undefined() }
hello_hello is offline   Reply With Quote
Old 18th April 2019, 20:38   #9  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Also, just to be a bit pedantic,

Code:
catch(err_msg){ Zet = undefined() }
Undefined in v2.60+ only.

RT_Stats(), nearly any version.
Quote:
RT_Undefined()
Returns same as undefined() in v2.6. Defined(RT_Undefined()) would return false.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 18th April 2019, 21:15   #10  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Code:
Function MyGlobaVarExist(String Name) {
    try { Eval(name) ex=true} catch(err) { ex=false }
    return ex
}

blankclip

Fred = "blurt"
#Global Fred = "fart"

name="Fred"
try { Eval(name) existFred=true} catch(err) { existFred=false }

GlbExistFred=MyGlobaVarExist(name)

S1="Local(inline) Fred =" + String(existFred)
S2="Global Fred =" + String(GlbExistFred)
S=S1+"\n"+S2

subtitle(s,lsp=0)


EDIT: Variation (same result as above)
Code:
Function MyGlobaVarExist(String Name) {
    try { Eval(name) ex=true} catch(err) { ex=false }
    return ex
}

blankclip(width=196,height=64)


Fred = undefined    # exists but Undefined (Comment out both assignments for non exist)
#Global Fred = undefined

name="Fred"
try { Eval(name) existFred=true} catch(err) { existFred=false }

GlbExistFred=MyGlobaVarExist(name)

S1="Local(inline) Fred =" + String(existFred)
S2="Global Fred =" + String(GlbExistFred)
S=S1+"\n"+S2

subtitle(s,lsp=0)
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 18th April 2019 at 21:34.
StainlessS is offline   Reply With Quote
Old 18th April 2019, 22:09   #11  |  Link
Dreamject
Registered User
 
Join Date: Dec 2018
Posts: 140
%)
Dreamject is offline   Reply With Quote
Old 20th April 2019, 03:53   #12  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,823
Quote:
Originally Posted by StainlessS View Post
Also, just to be a bit pedantic,

Code:
catch(err_msg){ Zet = undefined() }
Undefined in v2.60+ only.

RT_Stats(), nearly any version.
I was looking at another script today and I thought I'd bumped across an interesting way of undefining variables, then I realised it's what RT_Undefined() does. So any function that doesn't return anything returns "undefined"? Now I understand what you were referring to. And there was I thinking RT_Undefined() must be some clever and complicated function.

function VeryUndefined(){}

try{ Fred=Fred }catch(err){ Fred=VeryUndefined() }
Name=Fred
What=Defined(Fred)

Last edited by hello_hello; 20th April 2019 at 03:55.
hello_hello is offline   Reply With Quote
Old 20th April 2019, 09:10   #13  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Code:
Function SyntheticUndefined(var "DontSupllyAnyValueAtAllToThisOptionalVariableWithAVeryLongName") { return DontSupllyAnyValueAtAllToThisOptionalVariablewithAVeryLongName }
Above untested [just done clean setup], must call without any named or unnamed arg (only of any use [if at all] in v2.58, as v2.6+ has Undefined).

EDIT: Yes, good one HH, just realized what your function does, and does it better than above rubbish [probably].
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 20th April 2019 at 09:14.
StainlessS is offline   Reply With Quote
Old 20th April 2019, 11:58   #14  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by hello_hello View Post
So any function that doesn't return anything returns "undefined"?
That's right. See User defined script functions:
Quote:
If a function body has no (explicit or implicit) return, a void value (ie a value of the 'undefined' type) is returned.
I remember adding that bit myself following this discussion (back in 2008!): Result of NOP()
(You will see there that stickboy had already written a function Undefined() way back then )
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 20th April 2019, 15:57   #15  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,823
Ah.... so nop() returns zero. You do learn something new every day.

subtitle(string(nop(), "%.20f"))
hello_hello is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:23.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.