我有一個函數作爲教程遊戲的一部分。如果條件滿足(如果對象==「代碼」),則有問題的功能應觸發另一功能函數不調用另一個函數
# 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。你左邊有一扇門。你的權利 有一個門。或者你可以繼續。
right你看到一個包含兩個對象的表:一個地圖和一個代碼翻譯器你可以帶一個對象你拿哪個對象? 代碼確定,你有代碼。現在你必須退出並繼續。然後
上面的函數是指人在送他們回到起點和提示輸入「超前」,在終端:
# 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?"
但開口()沒有被調用。相反,Python似乎完成腳本並退出。
您在調用該函數之前使用'return' ...返回後的任何內容都未執行 – Jeribo
'next'是python中的內置函數。你可能會考慮將你的變量重命名爲別的東西('next_'是一個可行的選擇) – SethMMorton