Hello. This is my first post, so I hope I'm not screwing this up too badly. I'm trying to get back into Python and coding in general after a 10ish year hiatus by making a snake game.
I'm creating a list of directions and a list of wait times for each snake body segment. When wait is 0 the snake body segments update their direction according accompanying list of directions. This works as intended until I attempt to clear the lists of unnecessary data by calling pop(). I'm assuming what's happening is because the list is being popped during the loop, the next iteration doesn't have the correct ranges, but I can't think of a clean alternative way to clean the list of used data.
Any insight would be appreciated. Thank you!
I'm creating a list of directions and a list of wait times for each snake body segment. When wait is 0 the snake body segments update their direction according accompanying list of directions. This works as intended until I attempt to clear the lists of unnecessary data by calling pop(). I'm assuming what's happening is because the list is being popped during the loop, the next iteration doesn't have the correct ranges, but I can't think of a clean alternative way to clean the list of used data.
Any insight would be appreciated. Thank you!
def change_direction(self, new_direction): if new_direction != self.snake_head.direction: self.snake_head.direction = new_direction for i in range(len(self.snake_body)): self.snake_body[i].wait.append(i+1) self.snake_body[i].directions.append(new_direction) def traffic_control(self): for x in range(len(self.snake_body)): for y in range(len(self.snake_body[x].wait)): self.snake_body[x].wait[y] -= 1 if self.snake_body[x].wait[y] == 0: self.snake_body[x].change_direction_body(self.snake_body[x].directions[y]) #list.pop(self.snake_body[x].wait, y) #list.pop(self.snake_body[x].directions, y)