[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Off-topic: Re: [pygame] Getting unknown error



"Eric Hunter" <hunter.eric1@xxxxxxxxx> wrote:
> I've never heard of this error before: UnboundLocalError: local variable
> 'rect' referenced before assignment

It's pretty much as the error describes - you're making a reference to
'rect' in a code path before a definition is found.

Just looking through your code, I see two assignments to "rect", one in
the global scope right after "import pickle" and one in the MainLoop
function, setting a local variable with the same name. If you want those
two variables to actually be the same variable, you want to declare rect
as global, perhaps at the top of MainLoop:

    def MainLoop(self):
        global rect
        [... and so on ...]

See also:
http://www.python.org/doc/faq/programming/#how-do-you-set-a-global-variable-in-a-function
http://zephyrfalcon.org/labs/python_pitfalls.html


-Dave LeCompte