View Full Version : How do globals etc interact at runtime?


MrPete
5th January 2015, 14:03
As I just said elsewhere, I think I'm close to understanding something significant.

IMPORTANT? I wonder if all of the following (particularly ScriptClip) depends on whether I'm using the default or the GRunT ScriptClip environment? Like most, I'm using GRunT...

Let me share a bit of concept-code... please help me understand how to do what I want.

I comment the following based on an almost-certainly-wrong guess of how it "really works"...

My goal for a slightly-sophisticated decimation routine:
a) Initialize and track the most-recently-emitted original clip frame number
b) Initialize and track the current state of a frame-analysis state machine. State is currently one of 0, 1 or 2. (FWIW, 0=Search, 1=SprocketLock, 2=OverallLock)

NOTE: I understand that "normally" one wants runtime code to be completely independent of which frame is being retrieved. QUESTION: is it 100% necessary to make that assumption? My limited experience says as long as one runs through the clip in sequence, start-to-finish (eg use Vdub "Run video analysis pass"), one can process frames reliably in-sequence.

#
# Top Level Code
# Values set during Parsing Phase
#
global lastoutTopLev = -1 # never sent yet
global MyStateTopLev = 0 # search

myclip = AviSource(...)
RestoreFilmFrames(myclip,...)

#
# END OF Top Level Code
#

function RestoreFilmFrames(clip,...)
{
#
# Nested locally but still set during Parsing Phase?
#
global lastoutLocal = -1
global MyStateLocal = 0

f0 = myclip.ScriptClip("""
#
# WHAT'S AVAILABLE HERE? lastoutTopLev? lastoutLocal? etc
# Does it depend on whether included in args?
MyStateLocal==0 ? ...
MyStateTopLev==0 ? ...


#
# Dummy code... decide whether to send current frame...
#
sendthis = True

# How do I set a "survivable" value?
global lastoutTopLev = sendthis ? current_frame : lastoutTopLev
global MyStateTopLev = newstate
global MyStateLocal = newstate
""",args="lastoutTopLev,MyStateTopLev,lastoutLocal,MyStateLocal")

return(f0);
}


I have lots of confused questions:

- Is it true that even global variables are invisible in ScriptClip unless included in args?
- Where can I / can I NOT set the initial value of a global/static variable?
- What does it take to retrieve and update the value of a global/static variable?
- Do I actually need to use "global"? Are "args" variables pass-by-reference or pass-by-value or something quite different?
- From a variable-initialization perspective, do I need to worry about the fact that frame-serving basically processes statements bottom-to-top of code?

StainlessS
5th January 2015, 14:49
Global variables are global, read/write everywhere, but need to use GLOBAL keyword when writing otherwise you are changing local
variable of same name instead. If you accidentally forget the GLOBAL keyword when writing, then will create local variable of same
name which 'hides' the global variable, and you will get seemingly weird results.
Args everywhere are pass by value only. (Strings pass pointer to string by value, not the string itself).

From a variable-initialization perspective, do I need to worry about the fact that frame-serving basically processes statements bottom-to-top of code?

I can only suggest that you look at other peoples code and learn by example, there be dragons in them there woods.

EDIT: If you want to know what is happening, I suggest that you use RT_Stats RT_Debug() and RT_DebugF() funcs and
DebugView to view action in real time, it will answer any questions you have about order of happening.

MrPete
5th January 2015, 17:28
I see that we have the Defined() function... do you know if there's any ability to:
a) Detect if a variable is global or not
b) View the stack (or equiv)

I have searched and not found anything like these... sure would help for accomplishing the observations you suggest! OTW, it appears that this will require careful coding of a pile of test cases. I don't actually see this documented well... yet. Maybe something I can contribute over time...

StainlessS
5th January 2015, 21:42
There is fn called something like rt_varexist that can tell the obvious , don't know if that can help.
Gonna have one last beer, or two.

Wilbert
5th January 2015, 23:45
I see that we have the Defined() function... do you know if there's any ability to:
a) Detect if a variable is global or not
One of you should make a feature request on sourceforge for that.

For detection of a local variable you can use ScriptEnvironment::GetVarDef. You can use that in ScriptClip and friends (see docs).
For detection of a global variable we should make a ScriptEnvironment::GetGlobalVarDef and replace var_table by global_var_table in its definition. I guess something like that should work.

MrPete
6th January 2015, 05:44
StainlessS, since you are a plugin dev and I am not, I leave that one to you.

Meanwhile, I think I have answered all of my questions on this topic. I will open a separate thread with what I have discovered. Most likely nothing new to the old timers, but fascinating for me!

THANK YOU for your patience.

StainlessS
6th January 2015, 13:19
StainlessS, since you are a plugin dev and I am not, I leave that one to you.


Oh no you won't, you can make the request, you do not have to be dev to do that.

MrPete
6th January 2015, 18:07
I'm just saying I don't yet understand what I'm asking for at that level. :)

When Wilbert wrote
ScriptEnvironment::GetVarDef. You can use that in ScriptClip and friends

... I assumed that meant GetVarDef was somehow actually available for runtime scripting in ScriptClip() -- but I couldn't find a way to do it.

Clearly it somehow IS available in C++ / plugin world.

<Whine>
Do I **really** have to become a plugin coder to use this well, Daddy?
</Whine>
:rolleyes:

I don't currently even have a compiler environment installed...

StainlessS
6th January 2015, 19:11
Stop with the whimpering and whining, Ok I'll do it. :)

MrPete
6th January 2015, 20:16
I'll get there... just not many Round Tuits these days due to my Real World (selling and buying our home, taking care of family, plus gotta find $$ for my nonprofit org'n so we can eat...)

I'm working to simplify other things and generate time to help out. I'm actually a full-time "servant" around the world... which makes me too popular for my own good ;)

Given some time, I'll ramp up on this and hopefully be in a position to do something actually Useful one of these days.

StainlessS, I surely resonate with your model :)

MrPete
11th March 2022, 00:15
(Resurrecting one of my Very Old Threads... I've been hugely distracted for a while, but heading back into this. For any who may have interest or boredom, search for the following short story (and a link at the end to an even more amazing 100% true story, with only one gross photo ;) )... Pete tries to go to heaven again

:-D

shae
11th March 2022, 02:45
Welcome back Pete. :)