Python: Global name "True" and "bool" not defined.

While working in blender on a game, I have, at least twice, found an epic failure in scoping: first, builtin data types and functions cannot be defined (as in the thread name). In addition, when using class methods, you cannot use globally defined modules (eg GameLogic), and instead are forced to pass in GameLogic as a argument. ( and no, having it as a default argument does not work.) Note: this only happens in user defined class methods, and never in operator overloading methods (init). In addition, it is not predictable, and both times I have simply rewritten the same algorithm in slightly different wording. Does anyone know why this happens? I suspect it is something with the way the python script is integrated into the c engine. Maybe a bug?

I suspect it has something to do with how things are loaded - assuming your class is in a separate file, when blender initially compiles it to bytecode, GameLogic doesn’t exist (this is just a guess).

Though, I can certainly say that I know what you’re talking about: I get around it by passing the required modules in as arguments, storing that to a local class member, and than using that instead.

So in the case of GameLogic:


class MyClass:
    
    def __init__(self, GL):
        self.GL = GL

    def myMethod(self):
        self.GL.showMouse(1)

Then I would initialize it like this in the main controller script:


my_object = MyClass(GameLogic)