< Previous | Contents | Manuals Home | Boris FX | Next >
Persistent Global Variables
Normally, the variables created during the execution of a script are promptly forgotten as soon as the script terminates. Each script starts over from scratch, which simplifies writing reliable and predictable scripts. However, for workflow integration and specialized toolsets, it can be helpful to have persistent variables that last from one script to the next.
A special storage area, Global, provides this functionality. Global is a pseudo-object that can be accessed via attributes or as an indexed or associative list.
Using attributes, you can write: Global.myVar = 1 and Global.anotherVar = (“Tracker” Global.myVar). Or, use the associative version Global[“myVar”] or nm
= “myVar”; Global[nm] = 2. The attributes and associative list interfaces both access the same underlying data: Global.myVar == Global[“myVar”].
You can also treat Global as an indexed list with #Global and Global[1], Global[2], etc. You can do this if you want to see what Global contains, or to write all values to a file. To obtain the attribute names (associative list keys), use the Global.Key(nnn) function.
Remove items from the Global store with Global.Delete(“myVar”) or Global.Delete(3).
Fine print:
Globals are not preserved from one SynthEyes run to the next—each time you start SynthEyes the variables are cleared.
Do not store SynthEyes objects in globals: trackers, objects, shots, etc. Those values are not the same from one script execution to the next. Breaking this rule will result in a crash or, even worse, undetected mayhem. Store the uniqueID of the tracker etc, which is a plain string. Numbers, strings, points, vectors, transforms and lists of these items are OK.
The changes made to the globals are not recorded in the Undo system. If you run a script that changes the globals, then hit Undo, the SynthEyes scene will be restored to its state from before the script, but the globals will not be restored, they will remain changed. This should be a better typical choice for setup information (versus having the global changes undo also).
Be aware that the user may have changed scene files, hit Undo, etc, between script executions. Any saved data should be examined carefully.
©2024 Boris FX, Inc. — UNOFFICIAL — Converted from original PDF.