Quote:
Originally Posted by johnmeyer
I get my wrist slapped by Gavino every time I use global variables.
|
And rightly so
The above Multi-instance function, provides unique named Functions and unique named Globals,
and so are safe to use in multi-instance, so long as below name is unique in the entire script, (multi-instance use in same script ok)
in this case I've just used "MX".
You cannot have two different multi-instance functions both using the same GIFunc name (ie 'MX')
Code:
GIFunc ="MX" # Function Name, Supply unique name for your multi-instance function.
With two instances produces these results:- (The RT_WriteFile() line uncommented)
DEBUG_MX_1.TXT
Code:
Function Fn_MX_1(clip c1,clip c2,Bool Show,String Fmt) {
c1
n = current_frame
If(Prev_MX_1 == n) { # Cache failure, requested same frame again.
RT_DebugF("%d ] Cache Failure",n,name="Fn_MX_1_DBUG: ")
} Else If(Prev_MX_1 + 1 != n) { # Init OR Rewind OR User jumped about, dont you just hate users!
if(n == 0) {
if(Prev_MX_1 == -666) {
RT_DebugF("%d ] Initialized to frame 0",n,name="Fn_MX_1_DBUG: ")
} else {
RT_DebugF("%d ] Rewind to frame 0",n,name="Fn_MX_1_DBUG: ")
}
} else {
RT_DebugF("%d ] User Jumped About",n,name="Fn_MX_1_DBUG: ")
}
}
if(Show) {
RT_Subtitle(Fmt,n, c1.RT_AverageLuma(n=n), c2.RT_AverageLuma(n=n))
}
Global Prev_MX_1=current_Frame # Previous frame (For next interation jump about detect)
Return Last
}
#######################################
# Unique Global Variables Initialization
#######################################
Global Prev_MX_1= -666 # Init vars, Prev = -666 forces initalize
#######################################
# Unique Runtime Call, GScriptClip must be a one-liner:
#######################################
ARGS = "c2,Show,Fmt"
c1.GScriptClip("Fn_MX_1(last, "+ARGS+")", local=true, args=ARGS)
DEBUG_MX_2.TXT
Code:
Function Fn_MX_2(clip c1,clip c2,Bool Show,String Fmt) {
c1
n = current_frame
If(Prev_MX_2 == n) { # Cache failure, requested same frame again.
RT_DebugF("%d ] Cache Failure",n,name="Fn_MX_2_DBUG: ")
} Else If(Prev_MX_2 + 1 != n) { # Init OR Rewind OR User jumped about, dont you just hate users!
if(n == 0) {
if(Prev_MX_2 == -666) {
RT_DebugF("%d ] Initialized to frame 0",n,name="Fn_MX_2_DBUG: ")
} else {
RT_DebugF("%d ] Rewind to frame 0",n,name="Fn_MX_2_DBUG: ")
}
} else {
RT_DebugF("%d ] User Jumped About",n,name="Fn_MX_2_DBUG: ")
}
}
if(Show) {
RT_Subtitle(Fmt,n, c1.RT_AverageLuma(n=n), c2.RT_AverageLuma(n=n))
}
Global Prev_MX_2=current_Frame # Previous frame (For next interation jump about detect)
Return Last
}
#######################################
# Unique Global Variables Initialization
#######################################
Global Prev_MX_2= -666 # Init vars, Prev = -666 forces initalize
#######################################
# Unique Runtime Call, GScriptClip must be a one-liner:
#######################################
ARGS = "c2,Show,Fmt"
c1.GScriptClip("Fn_MX_2(last, "+ARGS+")", local=true, args=ARGS)
I feel quite sure that the big G would not give you a hard time for using such an arrangement as above,
seeing as he was party to its conception.
EDIT: The unique calling code is below the actual unique functions.
EDIT: Produces this in DebugView on first frame
Code:
[4024] Fn_MX_1_DBUG: 0 ] Initialized to frame 0
[4024] Fn_MX_2_DBUG: 0 ] Initialized to frame 0