Reputation: 95
I've got next error:
Traceback (most recent call last):
File "DungeonGame.py", line 92, in <module>
possible = possibleMoves(locations["player"])
File "DungeonGame.py", line 65, in possibleMoves
if player[0][0] == 0:
TypeError: 'int' object is not subscriptable
Here is my code:
def possibleMoves(player):
options = ["RIGHT", "LEFT", "UP", "DOWN"]
if player[0][0] == 0:
options.remove("LEFT")
elif player[0][0] == 4:
options.remove("RIGHT")
elif player[0][1] == 0:
options.remove("DOWN")
elif player[0][1] == 4:
options.remove("UP")
return options
...
locations = {"monster" : (1, 2), "door" : (3, 2), "player" : (4, 1)}
possible = possibleMoves(locations["player"])
Could someone help me with this?
Upvotes: 0
Views: 1029
Reputation: 30473
Here is the reason why you get the error:
player[0][0] == (4, 1)[0][0] == 4[0]
You pass locations["player"]
to possibleMoves(player)
, so player == locations["player"] == (4, 1)
.
Upvotes: 5