자습서를위한 게임의 일부로 함수가 있습니다. 해당 함수는 조건이 충족되면 다른 함수를 트리거해야합니다 (theobject == "code"인 경우)함수가 다른 함수를 호출하지 않음
# right room
def right_room():
print "You see a table with two objects: a map and a code translator"
print "You can take one object"
print "Which object do you take?"
next = raw_input("> ")
if "map" in next and "code" in next:
dead("You're greed surpassed your wisdom.")
elif "map" in next:
print "OK, you have the map."
theobject = "map"
print "Now you must exit and go ahead"
return theobject
opening()
elif "code" in next:
print "OK, you have the code."
theobject = "code"
print "Now you must exit and go ahead."
return theobject
opening()
오프닝이 호출되지 않습니까? 출력은 다음과 같습니다.
당신은 Labrynthe에 있습니다. 왼쪽에 문이 있습니다. 오른쪽에 에 문이 있습니다. 아니면 앞으로 나아갈 수 있습니다.
오른쪽지도와 코드 변환기 두 개의 개체가있는 테이블을 볼 수 있습니다. 하나의 개체를 사용할 수 있습니다. 어느 개체를 사용합니까? 코드 OK, 코드가 있습니다. 이제 나가서 계속해야합니다.
위의 기능은 다음 터미널에 "앞으로"입력에 다시 시작과 힌트에 사람을 보내는 의미 :
# opening scene
def opening():
print "You're in a Labrynthe."
print "There's a door on your left."
print "There's a door on your right."
print "Or you can go ahead."
next = raw_input("> ")
if "right" in next:
right_room()
elif "left" in next:
left_room()
elif "ahead" in next:
ahead()
else:
print "Which way will you go?"
그러나 개방()가 호출되지 않습니다. 대신 파이썬은 스크립트를 완료하고 종료하는 것처럼 보입니다.
그 함수를 호출하기 전에'return'을 사용하고 있습니다 ... 리턴 된 후에 아무것도 실행되지 않습니다 – Jeribo
'next'는 파이썬의 내장 함수입니다. 변수의 이름을 다른 것으로 바꿀 수도 있습니다 ('next_'가 실행 가능합니다) – SethMMorton