I can create one instance of this class, and it functions fine. However whenever a second instance is attempted to be created, even if the first object has been deleted, it returns an error. This is also odd because there is a class identical to this one, which can have as many instances created as needed with no errors.
Object is being made the exact same way both times.
class GOAL(pygame.sprite.Sprite):
def __init__(self,spawnx,spawny):
super().__init__()
self.image = goal
self.surf = pygame.Surface(self.image.get_rect().size)
self.rect = self.image.get_rect(topleft = (spawnx,spawny))
Class initiation code.
goal = GOAL((lineCount*100),(characterCount*100))
all_sprites.add(goal)
Class creation code.
Traceback (most recent call last):
File "C:\Users\User\Documents\python\pygame\simian shenanigans\simian shenanigans.py", line 975, in <module>
mainmenu()
File "C:\Users\User\Documents\python\pygame\simian shenanigans\simian shenanigans.py", line 689, in mainmenu
entity.clicked()
File "C:\Users\User\Documents\python\pygame\simian shenanigans\simian shenanigans.py", line 540, in clicked
self.sendfunction()
File "C:\Users\User\Documents\python\pygame\simian shenanigans\simian shenanigans.py", line 732, in playmenu
entity.clicked()
File "C:\Users\User\Documents\python\pygame\simian shenanigans\simian shenanigans.py", line 540, in clicked
self.sendfunction()
File "C:\Users\User\Documents\python\pygame\simian shenanigans\simian shenanigans.py", line 768, in level1
levelgeneration(levelToGenerate,all_sprites,enemies,walls,playerGroup)
File "C:\Users\User\Documents\python\pygame\simian shenanigans\simian shenanigans.py", line 903, in levelgeneration
goal = GOAL((lineCount*100),(characterCount*100))
File "C:\Users\User\Documents\python\pygame\simian shenanigans\simian shenanigans.py", line 638, in __init__
self.surf = pygame.Surface(self.image.get_rect().size)
AttributeError: 'GOAL' object has no attribute 'get_rect'
Error code.
Please ask if any other code required to be shown. Whole thing is 1000 lines and not all relevant so I have tried to include necessary code.