justking14 / endgame-singularity

Automatically exported from code.google.com/p/endgame-singularity
0 stars 0 forks source link

UnboUnboundLocalError: local variable 'handlers' referenced before assignment #80

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hello,

I've had a bug with your game.
Playing with my laptop, when I tried a "horizontal scroll" I got :

Traceback (most recent call last):
  File "singularity.py", line 1, in <module>
    import code.singularity
  File "/usr/share/games/singularity/code/singularity.py", line 226, in
<module>
    menu_screen.show()
  File "/usr/share/games/singularity/code/graphics/dialog.py", line 189, in
show
    result = self.handle(event)
  File "/usr/share/games/singularity/code/graphics/dialog.py", line 320, in
handle
    return self.call_handlers(handlers, event)
UnboundLocalError: local variable 'handlers' referenced before assignment

And of course, the game crashed.
I tried to fix this bug because apparently, some other bugs are related to
this one (UnboUnboundLocalError). Because I'm not really a good python
programmer and not a pygame programmer, I made a fix that you may improve.
In code/graphics/dialog.py in the handle(self, event) function, I had at
the beginning handlers=[] to assign the handlers variable. So it looks like :

    def handle(self, event):
        """Sends an event through all the applicable handlers, returning
           constants.NO_RESULT if the event goes unhandled or is handled
without
           requesting the dialog to exit.  Otherwise, returns the value
provided
           by the handler."""
        # Get the applicable handlers.  The handlers lists are all sorted.
        # If more than one handler type is applicable, we use [:] to make a
        # copy of the first type's list, then insort_all to insert the elements
        # of the other lists in proper sorted order.
    handlers=[]
        if event.type == pygame.MOUSEMOTION:

It seems to work pretty well.
BTW, nice game :D

Original issue reported on code.google.com by netantho on 11 May 2009 at 3:36

GoogleCodeExporter commented 8 years ago
Should be fixed in r942.  Thanks.

Original comment by phil.bor...@gmail.com on 23 May 2009 at 3:30