I've been trying to create a game with PyGame but sometimes it crashes due to this error:
ValueError: <main.projectile object at 0x0000024699C2C670> is not in list
Do you know any possible fixes?
As I've seen from other people it might be that I am modifying the bullets list while I'm iterating it but i can't find a solution even reading to this thread.
PS. I know that I can use a function to spawn the goblins and not just copy and paste but this is a quick project that I am trying to get over. This is the code:
def enemy():
def __init__(self, x, y, width, height, end):
self.x = x
self.y = y
self.width = width
self.height = height
self.end = end
self.path = [self.x, self.end]
self.walkCount = 0
self.vel = 3
self.hitbox = (self.x + 17, self.y + 2, 31, 57)
self.health = 10
self.visible = True
bullets = []
goblin = enemy(100, 410, 64, 64, 450)
# mainloop
while run:
if not goblin.visible:
goblin.hitbox = 0
for bullet in bullets:
if 0 < bullet.x < 500:
bullet.x += bullet.vel
else:
if len(bullets) != 0:
bullets.pop(bullets.index(bullet))