View Full Version : changing Global variable inside a function
gwendolien
2nd July 2013, 15:57
I'm trying to change a Global variable inside a function with the aim of deciding to call a second function yes or not.
Global X0=0
Global Y0=0
vhs_aligned=ScriptClip(vhsfull_z, """LumaDiff_alt(vhsdvd_z, dvd_z, 2, 2, 30, false)""")
(Abs(X0)==2 || Abs(Y0)==2) ? vhs_aligned=ScriptClip(vhsfull_z, """LumaDiff_alt(vhsdvd_z, dvd_z, 3, 23 , 30, true)""") : vhs_aligned
return vhs_aligned.Subtitle(String(X0)+" / "+String(Y0)
function LumaDiff_alt(......bool extra)
{
.
.
Global X0=BestX
Global Y0=BestY
return clip c.Subtitle(String(X0)+" / "+Strihg(Y0))
}
The values shown are always X0=0 and Y0=0....
The returned clip c does show the right values for X0 Y0,
but the vhs_aligned clip does only show 0,0....
What should be changed in my script?
Gavino
2nd July 2013, 22:44
X0 and Y0 are changed only at run-time (when LumaDiff_alt is called from ScriptClip()), so you cannot see their new values at outer script level (which is evaluated at compile-time).
You need to do everything at run-time in a new ScriptClip() which combines your existing ones.
vhs_aligned=ScriptClip(vhsfull_z, """
LumaDiff_alt(vhsdvd_z, dvd_z, 2, 2, 30, false)
(Abs(X0)==2 || Abs(Y0)==2) ? LumaDiff_alt(vhsdvd_z, dvd_z, 3, 23 , 30, true) : nop
return Subtitle(String(X0)+" / "+String(Y0)
""")
gwendolien
3rd July 2013, 07:50
Thanks Gavino!
I was afraid of this answer because what I really am after is using the outcome of LumaDiff_alt for frame n, as a start for frame n+1 thorughout the whole clip.
This because of the present speed of the whole script of around 0.3 fps.... After all, most frames look a lot like the previous one...
Do you have any suggestion as how to tackle this problem of using the results of a previous frame as a starting point for the present frame over the whole movie?
Gavino
3rd July 2013, 09:05
Do you have any suggestion as how to tackle this problem of using the results of a previous frame as a starting point for the present frame over the whole movie?
As the run-time script is evaluated once per frame, the general way to tackle this is to update one or more variables on each frame and use these to decide what to do on the next frame. You already have your variables X0 and Y0, so you are almost there.
In outline:
ScriptClip("""
... # here X0 and Y0 are from previous frame
... LumaDiff_alt(...) # process as necessary, updating X0 and Y0
... # here X0 and Y0 are from current frame
""")
For this to work, the frames must be rendered sequentially from start to finish (no jumps in timeline).
gwendolien
3rd July 2013, 13:45
I got a solution like processing the whole movie WITHIN one ScriptClip, since, as soon as you step out of that ScriptClip, the X0 Y0 values are not available anymore.
It means that I have to save the result as an intermediate movie and do all the other processing in a separate script altogether. Thanks a lot for your response!
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.