In the following code, I defined self.dir
in the match case
class Enemies(pygame.sprite.Sprite):
def __init__(self):
self.image = pygame.image.load("picture.png").convert_alpha()
self.seat = random.choices(
(range(1, 13)), weights=(1, 3, 3, 1, 3, 3, 1, 3, 3, 1, 3, 3))
match self.seat:
case 1:
self.dir = 315
self.rect = self.image.get_rect(bottomright=(0, 0))
# there are many more cases but they are similar
print(self.dir)
When I run the code, in the print(self.dir)
part, it returned an AttributeError. But I defined self.dir
in the match case. Do you think it is match case's problem or am I missing something?
Edit: it's not the match case's problem. random.choices() returns a list and in the match case, it needs an int.