Home > Software engineering >  Python "Maximum Recursion Depth Exceeded Error"
Python "Maximum Recursion Depth Exceeded Error"

Time:10-26

    def updatedcollisions(self):
        self.xcord, self.ycord = pygame.mouse.get_pos()
        if self.confirmationscreen == True:
            if self.xcord < 150 or self.xcord > 650 and self.ycord < 200 or self.ycord > 700:
                print('Out of Screen')
                self.confirmationscreen = False
                pygame.Surface.fill(self.win,('black'))
                self.loadonce()
                self.buttons()
                self.font = pygame.font.Font(r'D:\Games\First Game\FreeSans\FreeSansBold.ttf',28)
                self.text = self.font.render(f'Multiplier {self.moneyperclick}', True, (255,255,255))
                self.textRect = self.text.get_rect()
                self.textRect.center = (self.width//2, 150)
                pygame.draw.rect(self.win,(0,0,0),self.textRect)
                self.win.blit(self.text, self.textRect)
        else:
            if 300 <= self.xcord <= 400 and 600 <= self.ycord <= 700:
                self.win.blit(self.whiteboard,[(self.width/2)-150,(self.height/2)-200])
                self.multiplier()
                self.confirmation()
            elif 150 <=self.xcord <= 250 and 600 <= self.ycord <=700:
                print('Worked')
                self.money = self.money - self.moneyperclick
                pygame.display.update()
            else:
                self.whiteboardfiller()
                self.updatedcollisions()
                self.moneytracker()
                self.money = round(self.money,2)
                self.changingtextstuff(f'Whiteboards {self.money}')

I did some research and found that it means that it is looping through something but I don't understand why it isn't able to process this. Error message also says if type(random) is BuiltInMethod or type(getrandbits) is Method:. If anyone could help that would be awesome. Full code is here.

CodePudding user response:

Maximum Recursion Depth Exceeded means that your code has called itself too many times for the interpreter to process. In this case, I believe that the culprit is self.updatedcollisions() in your second else statement.

Let's say that you called updatedcollisions() in your code. If confirmationscreen is false, then it jumps to the first else block. In that else block, if this object is not in the correct bounds (the if and elif statements are both false), the code jumps to the final else block. Within the final else block, updatedcollisions() is called again, and the cycle repeats over and over until the recursion is too deep to process, crashing the program.

  • Related