Log in

View Full Version : problem: Import avs script and named variables


grannyGeek
2nd July 2007, 09:11
Every time I start to fool myself into believing I'm getting a handle on this stuff, the noob stick flies up and whacks me in the face.

Using VDubMod 1.5.10.2 , VirtualDub 1.6.19, and AviSynth 2.57
When I import an avs script into my main script that has some of the same names used for variables, the main script processes the import before it does the main script.
(confused yet???)


For example
my main script has some named variables for clips

vpath = "C:\Captures\"
a = avisource(vpath +"blahblah.avi").trim(15,1500)
b - avisource(vpath + "blah2.avi").trim(75,9000)
c = import(vpath+"manyTrims.avs")

A+B+C

Now, the "manyTrims" script also has other clips named
a, b, c.

When I load the Main script, the a, b, c clips listed in the imported "ManyTrims" avs appear on the timeline first, then the A and B clips listed in Main script.

I tried this with two separate scripts, it happened both times.
I ended up going into the imported scripts and changing the variable names so there would be no conflict.

I used to do this frequently with AviSynth 2.55, and it never happened then.

So, is this a change in the way the new AviSynth version handles imported scripts, or is it user error?
If it is my error, what am I doing wrong, and how do I fix it?

Thanks in advance for any input ---
Regards -
granny

Leak
2nd July 2007, 09:31
So, is this a change in the way the new AviSynth version handles imported scripts, or is it user error?
If it is my error, what am I doing wrong, and how do I fix it?
Well, going strictly by the documentation only variables that are explicitly declared as global, functions and the value returned should be available outside of the imported script, so if the variables a, b and c in your imported script overwrite the a, b and c in the script that's importing it it sounds like a bug - unless I'm overlooking something.

IanB
2nd July 2007, 10:15
@grannyGeek,

Import() is a simple textual include of the named scripts contents in place of the Import statement.

@Leak,

To which documentation do you refer? It may need some attention.

Leak
2nd July 2007, 10:56
@Leak,

To which documentation do you refer? It may need some attention.
.../AviSynth 2.5/Docs/english/corefilters/import.htm

Import

Import (string filename)

Import evaluates the contents of another AviSynth script.

Globals declared inside the imported script (functions, global variables, loaded plugins) are made available to the importing script. In addition, the return value of the function is the return value of the filename script (a clip or whatever the filename script chooses to return). The later can be assigned to a variable of the importing script and manipulated (this is most useful when the imported script returns a clip).

Some indicative uses of Import include:

* Storing multiple script-functions and global variables for reuse by scripts (creation of script libraries).
* Retrieving pre-built streams.
* Retrieving dynamically configured pre-built streams (the core idea is: the importing script declares some global variables which the imported script uses to configure the stream that will return).

$Date: 2005/11/17 20:18:13 $

foxyshadis
2nd July 2007, 17:02
One way to avoid that behavior is to use c=AviSource(vpath+"manyTrims.avs"), which creates a totally separate environment for that script before returning the results; the downside is that you don't get any of the functions imported, and it may have some overhead. Then again, it's generally a pretty bad idea to mix utility and functional scripts anyway. You can also do this for a little less overhead:

function scriptc() { import(vpath+"manyTrims.avs") }
c = scriptc()

I just find avisource a little more convenient. (Especially since it enforces linear seek within a short range.)

grannyGeek
3rd July 2007, 06:39
Guys, thanks for responses.

Foxyshadis, I will start using Avisource --- I do love simple solutions :)

I'm almost positive that the calling script used to give priority to its own variables, and the import script variables came second. Maybe my memory died with my old computer, and I can't retrieve any of my old scripts.

:thanks:

tin3tin
3rd July 2007, 07:22
Here's what worked for me: :)
http://forum.doom9.org/showthread.php?t=125510