I am trying to fix a very simple pygame minigame but I'm not very familiar with dictionaries. So I have a dictionary with four monsters (keys) and their respective starting positions as values in a list. For drawing them with pygame or make them move I wanted to use a for-loop to iterate through the dictionary, but it seems like I can't index the value of a dictionary, so I'm a bit stuck.
Below is what I was trying for drawing the monsters:
monsterStart={"M1":[40,40], "M2":[580,40], "M3":[40,380], "M4":[580,380]}
global monsterStart
def drawMonsters(monsters):
monsters=monsterStart
for monster in monsters:
monsterPosition = monsters[monster]
MP_x = monsterPosition[0]
MP_y = monsterPosition[1]
pygame.draw.rect(DISPLAYSURFACE, Blue, (MP_x, MP_y, 20, 20))
drawMonsters(monsterStart)
When I try to run my code it gives me this error:
Traceback (most recent call last):
File "cave_room_bonus.py", line 457, in drawMonsters
monsterPosition = monsters[monster]
TypeError: tuple indices must be integers or slices, not dict
And unfortunately, I can't figure out what's wrong or think of another way to program this. I'm rather new in the world of programming, so I would appreciate some help!