Chrispresso / SuperMarioBros-AI

332 stars 69 forks source link

Pressing [Control] crashes the script #3

Closed MariTort closed 3 years ago

MariTort commented 3 years ago

Pressing control while running Mario will cause an immediate crash. I found the issue to be in smb_ai.py (line 520) and assumed I accidentally commented this out when I learning from your code.

But it seems I did not, I redownloaded and it was still present

 def keyPressEvent(self, event):
        # k = event.key()
        # m = {
        #     Qt.Key_Right : 7,
        #     Qt.Key_C : 8,
        #     Qt.Key_X: 0,
        #     Qt.Key_Left: 6,
        #     Qt.Key_Down: 5
        # }
        # if k in m:
        #     self.keys[m[k]] = 1
        # if k == Qt.Key_D:
        #     tiles = SMB.get_tiles(self.env.get_ram(), False)
        modifier = int(event.modifiers())
        if modifier == Qt.CTRL:
            if k == Qt.Key_V:
                self._should_display = not self._should_display

edit: I would include the error, but as it requires intentional crashing, and I finally have him running again I would rather not :)

edit2: Nevermind, I'm an idiot and did it anyway... here's the error Traceback (most recent call last): File "smb_ai.py", line 517, in keyPressEvent if k == Qt.Key_V: NameError: name 'k' is not defined

shuishen49 commented 3 years ago
        modifier = int(event.modifiers())
        if modifier == Qt.CTRL:
            k = event.key()
            if k == Qt.Key_V:
                self._should_display = not self._should_display

inster this k = event.key()

Chrispresso commented 3 years ago

Thanks for pointing that out. It is now fixed. You can either pull the latest change or uncomment the line k = event.key(). That is the only thing that needed to change. Accidentally commented it out during a previous commit I guess.