Python -- TypeError: int object is not subscriptable

Python -- TypeError: int object is not subscriptable

我有下一个错误:

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

这是我的代码:

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"])

有人可以帮我解决这个问题吗?

这是您收到错误的原因:

player[0][0] == (4, 1)[0][0] == 4[0]

您将 locations["player"] 传递给 possibleMoves(player),因此 player == locations["player"] == (4, 1)