I wanted to have some global variables in an addon.
But doing so, some parts of the script were not able to access these variables. I had an error message saying I can not use them as they are not initialized.
In this addon, I took some parts of code I have found here, in order to draw on the 3D View. The draw callback of the 'DrawingClass' in this code is able to see these global variables.
But in the operator itself, it does not work.
I have found a workaround setting these variables as class variable of the operator. So... 'it works' (even if the code is not very nice, currently).
But why some execution contexts (the drawing callback) allow to use these globals and not some others (invoke or execute of an operator) ?
I don't put the code directly here, as it is a bit long. But here is the blend file :
The variables are "inactive" and "replaceMode" which can be found in the "grsOperator" class. The script simply replaces the G, R, S keys standard behavior by the corresponding manipulator. On the bottom left of the 3D view, you can click on a square in order to change the mode ("replaceMode") or disable the key interception ("inactive").
global inactive
will fix the not initialized error. Check out blender.stackexchange.com/a/41329/15543 $\endgroup$