С моей стороны уже поздно спрашивать, учитывая, что это какой-то запоздалый школьный проект, но я подумал, что у меня что-то происходит, когда я занялся программированием своего маленького кода для игры в подземелье с текстом аромата и именами для монстров и так далее. , Внезапно, когда я попытался запустить код и подняться наверх, меня поразило следующее:
Traceback (most recent call last):
File "python", line 220, in <module>
File "python", line 199, in Options
File "python", line 115, in Movement
UnboundLocalError: local variable 'print' referenced before assignment
Я не совсем уверен, как мне удалось сделать локальную переменную из ключевого слова, хотя Я полагаю, что то, что находится внутри пользовательской функции - это то, что выбрасывает все это из строя. Данный код выглядит так:
def Movement():
#move in cardinal directions, wherever possible
#input is the direction you want to go
#output is the ensuing change in position, whether it be vertical or horizontal
global Position
global Room
direction=str(input("Where do you want to go?"))
if direction=='up' or direction=='Up' or direction=='UP':
if 'staircase up' in Position:
Floor +=1
else:
print("You wish you could climb the walls, but you need some stairs to go up for now.")
if 'staircase down' in Position:
Floor -=1
else:
print:("You could jump out a window, but that'd probably be lethal; best to stick with stairs for now.")
if (direction=='left' or direction=='Left' or direction=='LEFT') and Room>0 and not(('ANGRY HOG' or
'BLIND DRAGON') in Position):
Room -=1
Room +=1
else:
print("That's not going to work.")