私は何が間違っているのか分かりません。私はあまりにも長くそれを主演しており、問題を見つけるのを助ける必要があります。ここNoneTypeオブジェクトには、テキスト冒険のための属性 'get'がありません
def get_player_command():
"""the player input"""
return raw_input('Action: ').lower().strip()
def play():
print("++++++++++++++++++++++++++++++++++")
print("| DEATHSCHOOL!!!! |")
print("| |")
print("++++++++++++++++++++++++++++++++++\n\n\n")
print("You walk up the stairs on the first day of school.\n Something doesn't feel right......\n The parking lot was full, but the building is eerily silent.\n")
player = Player()
while True:
room = world.tile_at(player.x, player.y)
print(room.intro_text())
room.modify_player(player)
choose_action(room, player)
def action_adder(action_dict, hotkey, action, name):
action_dict[hotkey.lower()] = action
action_dict[hotkey.upper()] = action
print("{}: {}".format(hotkey, name))
def get_available_actions(room,player):
actions = collections.OrderedDict()
print ("Choose an action: ")
if player.backpack:
action_adder(actions, 'b', player.print_pack, "Print Backpack")
if isinstance (room, world.EnemyTile) and room.enemy.is_alive():
action_adder(actions, 'f', player.attack, "Fight!")
else:
if world.tile_at(room.x, room.y - 1):
action_adder(actions, 'w', player.move_forward, "Go Forward!")
if world.tile_at(room.x, room.y + 1):
action_adder(actions, 's', player.move_backward, "Go Backward!")
if world.tile_at(room.x + 1, room.y):
action_adder(actions, 'd', player.move_right, "Go Right!")
if world.tile_at(room.x - 1, room.y):
action_adder(actions, 'a', player.move_left, "Go Left!")
if player.lifepoints < 100:
action_adder(actions, 'h', player.heal, "Heal")
return actions
def choose_action(room, player):
action = None
while not action:
available_actions = get_available_actions(room, player)
action_input = raw_input("Action: ").lower().strip()
action = available_actions.get(action_input)
if action:
action()
else:
print("Invalid action!")
play()
は、それは私がW、SおよびBホットキーを使用せた、とだけ私が敵と戦うために、Fを使用し、エラーを与えていたトレースバック
Traceback (most recent call last):
File "E:\CoriSparks_Portfolio\DeathSchool\action.py", line 110, in <module>
play()
File "E:\CoriSparks_Portfolio\DeathSchool\action.py", line 60, in play
choose_action(room, player)
File "E:\CoriSparks_Portfolio\DeathSchool\action.py", line 103, in choose_action
action = available_actions.get(action_input)
AttributeError: 'NoneType' object has no attribute 'get'
最後の夜です。今は私が何をしてもエラーが出ます。また、それだけで 'と 『D』
NoneTypeオブジェクトの99%は属性がありません...誤って返された関数からエラーが発生しました。 – Gribouillis
これは単純なものでなければならないことを知っていました。ありがとうございました。すべてのアクションキーを印刷していない理由を教えてください。 –
私はそれを完全に理解した。ありがとう、ありがとう、ありがとう:) –