I'm developing an ObjectData deformer. I need to have some global variables in there, but I found some difficulty getting them right. I didn't find a clear explanation on how the plugin code is executed, so I'm struggling.
I tried to declare variables needed in the beginning of the file:
doc = c4d.documents.GetActiveDocument() fps = doc.GetFps() fC = None fP = None frameStored = 0 if fP != None: velocity = 1 else: velocity = 0
Some are working (the first two) but when I call for frameStored from the modifier class I get:
UnboundLocalError: local variable 'frameStored' referenced before assignment
So I thought to go the other way. A dedicated class to store and calculate some global vars, it's simple:
class storage(): fC = None fP = None frameStored = None if fP != None and fC != None : velocity = 1 else: velocity = 0
I create an object of that class inside of the plugin class (I use your handy example as a base so it's called so :D)
class SpherifyModifier(c4d.plugins.ObjectData): store = storage()
But store var becomes undefined 0_0
If I try "storage.frameStored" I can read and write that value! But it's wrong as there should not be an instance of the class! I didn't create it!
At the same time when I try to create it nothing works
But more is further - when something is calculating inside the class or in global space it does not update
For example, "velocity" is always 0, even when fC and fP are not "None" anymore but Vector type (I checked it numerous times)
I though the code itself is executed once when loading plugin and than Cinema calls the methods of c4d.plugins.ObjectData subclass as it needs. But it turns out the sequence is different?
I really can't get how it works. Can somebody lead me to an explanation please?