Answer the question
In order to leave comments, you need to log in
Problems in Python code?
def create_map():
global obstacles
locations = []
for i in range(10):
row = random.randint(0, 9)
col = random.randint(0, 9)
location = [col * 64 + 20, row * 64 + 20 + 640]
if not (location in locations):
locations.append(location)
type = random.choice(["tree", "flag"])
if type == "tree": img = ("d:\Python\skier_tree.png")
elif type == "flag": img = ("d:\Python\skier_flag.png")
obstacle = ObstacleClass(img, location, type)
obstacle.add(obstacle)
Traceback (most recent call last):
File "D:\Game Skier - 1.py", line 76, in <module>
create_map()
File "D:\Game Skier - 1.py", line 59, in create_map
obstacle.add(obstacle)
File "D:\Python\lib\site-packages\pygame\sprite.py", line 142, in add
self.add(*group)
TypeError: add() argument after * must be an iterable, not ObstacleClass
Answer the question
In order to leave comments, you need to log in
Staffic Good day!
First, indent your code.
And then you made a mistake on the last line. Compare your code and code from the book.
def create_map():
global obstacles
locations = []
for i in range(10):
row = random.randint(0, 9)
col = random.randint(0, 9)
location = [col * 64 + 20, row * 64 + 20 + 640]
if not (location in locations):
locations.append(location)
type = random.choice(["tree", "flag"])
if type == "tree": img = "skier_tree.png"
elif type == "flag": img = "skier_flag.png"
obstacle = ObstacleClass(img, location, type)
obstacles.add(obstacle)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question