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. |
22nd June 2012, 17:00 | #1 | Link |
Registered User
Join Date: Jan 2010
Posts: 5
|
User-def function not executing / global var access
Hi guys,
why is this script not working: Code:
global test=222 function bla() { test=1234 } bla() Version() ScriptClip("""subtitle(string(test))""") Thanks for help.
__________________
Greetings Rumpelmucke |
22nd June 2012, 17:11 | #2 | Link |
Registered User
Join Date: Apr 2002
Location: Germany
Posts: 5,391
|
Code:
global test=222 function bla() { global test=1234 } bla() Version() ScriptClip("""subtitle(string(test))""")
__________________
- We´re at the beginning of the end of mankind´s childhood - My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!) |
22nd June 2012, 17:23 | #3 | Link | ||
Registered User
Join Date: Jan 2010
Posts: 5
|
Quote:
Quote:
__________________
Greetings Rumpelmucke |
||
22nd June 2012, 18:40 | #4 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Yes, the key word is "To define and / or assign a value ...".
Without the word global, all assignments are local to the current scope. On a further point of information, note that a variable (like test above) does not need to be global to be used inside ScriptClip. It only needs to be defined at the outer script level. Of course, it does need to be global if you also want to change its value inside a function, like your bla(). |
22nd June 2012, 21:35 | #6 | Link |
Registered User
Join Date: Jan 2010
Posts: 5
|
Still problems... (full script)
I am still having problems changing global vars and reading them out.
The idea is to emulate a hand camera moving erratically up/down/left/right. I will smooth out the movement later, but heres the concept: (1) define a maximum range of movement (rng=20 pixels), +/- (2) generate 4 Random values between -rng and +rng (the function is designed to produce more values around zero than higher absolute values). These define two points x1/y1 and x2/y2. The "camera" will move from x1/y1 to x2/y2 with a defined number of steps. (3) when x2/y2 is reached, write x2/y2 to x1/y1, generate two new values for x2/y2 and move there. (4) function it() returns x and should set global y and global x. I use that technique often, use a function to return one and set a second value globally. So you return two values at once. The critical part is function it(int s). Actually all required global variables are being changed seemingly, but for some reason I cannot read global x, global y, global x1, global x2, global y1, global y2 out from within ScriptClip. With stepwx, stepwy it works! What can be the reason?? Code:
#AviSource("C:\somevideo.avi").converttoRGB32().killaudio() Version() # center of video (720 x 540) global cx=360 global cy=270 # starting point global x1=0 global y1=0 # target point global x2=0 global y2=0 # current position ###### function it(int s) should change these globally but I cannot read them out from outside this function!!!! global x=0 global y=0 # number of steps global steps=10 # step length global stepwx=0 global stepwy=0 # range of movement global rng=20 #### generate new coordinate in range function newp(int range) { r = Rand()-1 # 0 <-> 32767 sc = r/32767.0 para = sc*sc*sc*sc*sc*sc*sc new = para*float(range) return Rand(10)>5 ? -new : new # random sign } #### swap points and generate a new one function set() { # global x1=x2 global y1=y2 global x2=newp(rng) global y2=newp(rng) global stepwx=(x2-x1)/steps global stepwy=(y2-y1)/steps } #### iterate movement function it(int s) { # s= current step, current_frame modulus steps global step=s # DOES change global step !!! s==0 ? set() : nop() global x=x1+s*stepwx ####### does NOT seem to change global x !!! global y=y1+s*stepwy ####### does NOT seem to change global y !!! return x } # ----------------- start x=0.0 y=222 x1=0 y1=0 x2=100.0 #2! y2=0.0 #ScriptClip("""zoom(srcx=string(it(current_frame%steps)+cx),srcy=string(y+cy))""") ScriptClip("""subtitle(string(it(current_frame%steps)) + " | " + string(x) + " | " + string(y) + " | " + string(stepwy) + " | " + string(step))""")
__________________
Greetings Rumpelmucke |
22nd June 2012, 23:49 | #7 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
Because these variables now exist, they hide the global variables of the same name when those names are used at outer script level, including inside ScriptClip. |
|
23rd June 2012, 16:12 | #9 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
Global scope (which must always be explicitly indicated by the global keyword) is a different scope from 'script level' scope which applies at the outer level of a script (ie outside of functions) and inside run-time filters like ScriptClip. See http://avisynth.org/mediawiki/The_sc...e_of_variables. |
|
|
|