TypeError: unhashable type: 'list' In pyglet
Solution 1:
The problem is that the name pipes
is used twice. First is used for the OrderedGroup
of pipes. In this group, the initial pipe
batches are added:
pipes = pyglet.graphics.OrderedGroup(1)
However, it is then used for a list of pipes
. The original group pipes
is shadowed by the list of pipes and creating a new Pipe
object fails:
pipes = [Pipe()]
Use different names for the group and the list. Rename list:
pipes_list = [Pipe()]
time_created_pipe = 50
def update_char(dt):
global time_created_pipe, pipes_list
if bird.alive:
bird.update()
for pipe in pipes_list:
pipe.update()
if pipe.top_pipe.x <= -100:
pipes_list.remove(pipe)
if time_created_pipe <= 0:
time_created_pipe = 50
pipes_list.append(Pipe())
time_created_pipe -= 1