View Single Post
Old 27th April 2017, 10:52   #10  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
StainlessS has correctly described the available solutions.
You might think that this would also work:
Code:
Clip1 = ... # whatever
Clip2 = ... # whatever

Function Fn(clip ClipA, ClipB) {
  global GClipB = ClipB
  Return ClipA.ScriptClip("Subtitle(string(GClipB.AverageLuma))")
}

Fn(Clip1, Clip2)
and it does, but ...
as soon as you call the function more than once with different clips for ClipB, it goes badly wrong:
Code:
Clip1 = ... # whatever
Clip2 = ... # whatever
Clip3 = ... # whatever
...
Fn(Clip1, Clip2)
...
Fn(Clip1, Clip3)
Here, despite appearances, Clip3 will be used inside both ScriptClip instances.
The reason is that the second global assignment to GClipB happens at compile-time, before either of the two run-time scripts ("Subtitle(...)") are evaluated. Hence in both cases they see GClipB identified with Clip3.

Even without functions, you can get the following problem:
Code:
ClipA = ... # whatever
ClipB = ... # whatever
ClipA.ScriptClip("Subtitle(string(ClipB.AverageLuma))")
...
ClipB = ... # something else
...
Here, the value of ClipB inside the ScriptClip call will be the 'something else', not the original value, again because the second assignment happens before the run-time script is evaluated.

These are both examples of what I call the 'variable binding problem' and what led me to produce GRunT (which solves it).
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote