bREAkDoWN
29th April 2006, 14:40
Let's take the following code:
directshowsource("blabla.avi",fps=25)
converttoyv12()
global temp=0
ScriptClip("""Subtitle("temp: "+String(temp)) """)
ScriptClip("f1()")
ScriptClip("f2()")
function f1(clip c) {
c=FrameEvaluate(c,"temp=temp+1")
return(c)
}
function f2(clip c) {
c=FrameEvaluate(c,"temp=temp+2")
return(c)
}
This way everything works as supposed, and temp is incremented by 3 on every frame.
If i add "global" into frameevaluate in both functions: c=FrameEvaluate(c,"global temp=temp+1"), everything still works as expected.
I suppose that the right way should be the one without "global", because temp has already been initialized as global in the main script.
However, i started to have some doubts when i discovered by chance that if i put global into the frameevaluate of only one of the two functions, something strange will happen. In fact, on script execution, the first frame will show 3, which is the correct sum, but stepping ahead frame by frame, only the frameevaluate without global will contribute to the sum.
In other words:
directshowsource("blabla.avi",fps=25)
converttoyv12()
global temp=0
ScriptClip("""Subtitle("temp: "+String(temp)) """)
ScriptClip("f1()")
ScriptClip("f2()")
function f1(clip c) {
c=FrameEvaluate(c,"temp=temp+1")
return(c)
}
function f2(clip c) {
c=FrameEvaluate(c,"global temp=temp+2")
return(c)
}
will output:
3 4 5 6 7 instead of 3 6 9 12 15
Can someone explain why does this happen?
directshowsource("blabla.avi",fps=25)
converttoyv12()
global temp=0
ScriptClip("""Subtitle("temp: "+String(temp)) """)
ScriptClip("f1()")
ScriptClip("f2()")
function f1(clip c) {
c=FrameEvaluate(c,"temp=temp+1")
return(c)
}
function f2(clip c) {
c=FrameEvaluate(c,"temp=temp+2")
return(c)
}
This way everything works as supposed, and temp is incremented by 3 on every frame.
If i add "global" into frameevaluate in both functions: c=FrameEvaluate(c,"global temp=temp+1"), everything still works as expected.
I suppose that the right way should be the one without "global", because temp has already been initialized as global in the main script.
However, i started to have some doubts when i discovered by chance that if i put global into the frameevaluate of only one of the two functions, something strange will happen. In fact, on script execution, the first frame will show 3, which is the correct sum, but stepping ahead frame by frame, only the frameevaluate without global will contribute to the sum.
In other words:
directshowsource("blabla.avi",fps=25)
converttoyv12()
global temp=0
ScriptClip("""Subtitle("temp: "+String(temp)) """)
ScriptClip("f1()")
ScriptClip("f2()")
function f1(clip c) {
c=FrameEvaluate(c,"temp=temp+1")
return(c)
}
function f2(clip c) {
c=FrameEvaluate(c,"global temp=temp+2")
return(c)
}
will output:
3 4 5 6 7 instead of 3 6 9 12 15
Can someone explain why does this happen?