나는 입력을 치고 한 단어를 쓰는 동안 "범위를 벗어났습니다". 나는 그들이 범위를 벗어난 이유를 이해하고, 문제를 해결하는 방법을 찾을 수 없습니다. 나는이 통과 아니에요 실현목록 색인이 범위를 벗어났습니다?
commands = {
'help': help,
'exit': exit,
'look': look,
'stats': thePlayer.printStats,
's':thePlayer.move_South}
def runCmd(cmd, args, player):
commands[cmd](args, player)
def help(args):
print(commands)
def play():
main1()
World.loadTiles()
#These lines load the starting room and display the text
room = World.tileExists(player.locationX, player.locationY)
print(room.introText())
while player.isAlive():
room = World.tileExists(player.locationX, player.locationY)
room.modifyPlayer(player)
# Check again since the room could have changed the player's state
if player.isAlive():
print("\nHp:%d\%d Mp:%d\%d\n"%(player.hp,player.maxHp,player.mp,player.maxMp))
print(room.printEnemy())
availableActions = room.availableActions()
for action in availableActions:
print(action)
actionInput = input('Action: ')
action = actionInput.lower()
action = action.split()
print(action)
if action[0] in commands:
runCmd(action[0],action[1], player)
"조치를 [1]"를 입력 단지 타격하는 내 오류의 원인 "명령"에없는 것을이 내 코드입니다. 나는 코딩에 익숙하지 않으므로 게임을 만드는 것이 자신을 어떻게 가르쳐 주는지입니다.
입력, 한 단어 (도움말, 통계), 두 단어 (룩 보이기), 더 많은 단어가있는 다른 것들 (큰 칼 구매) 등등을 입력 할 수 있습니다. 이 코드를 올바르게 코딩 할 수있는 방법에 대한 도움이 필요하십니까?
매우 효과적 일 것입니다. 하지만 그것은 20 개의 여분의 코드를 몇 번 더 추가하여 간소화 할 수 있다고 확신합니다. 나는 패스 할 수있는 args가 있음을 알고있다. 대신 (필자의 지식에 따라) 내가 원하는만큼 내 논쟁을 통과 할 것이다. 그러나 나는 그것을 정확히 어떻게 사용해야할지 모른다. – Reederboard
나는 splat 연산자를 사용한 적이 없으므로 나는 당신을 도울 수 없다. 아마도 여기에 몇 가지 단서를 찾을 수 있습니다 (https://pythontips.com/2013/08/04/args-and-kwargs-in-python-explained/). 파이썬 2이지만 파이썬 3에서도 작동한다고 생각합니다. – Abrikot