簡體   English   中英

功能不調用另一個功能

[英]function not calling another function

我有一個功能作為教程游戲的一部分。 如果滿足條件,該問題的函數應該觸發另一個函數(如果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。 左邊有一扇門。 右邊有一扇門。 或者你可以繼續。

你看到一個有兩個對象的表:一個地圖和一個代碼翻譯你可以拿一個對象你拿哪個對象? 代碼好的,你有代碼。 現在你必須退出並繼續前進。

然后,上面的函數用於將人員發送回開頭,並提示他們在終端中輸入“提前”:

# 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?"

但是沒有調用opening()。 相反,Python似乎完成了腳本並退出。

Python中的return語句(以及幾乎所有語言 - Haskell的顯着例外 - )意味着函數應該在那里。 如果語句是return exprreturn expr的值可供調用者使用。 否則,在Python中,調用者可以使用值None

因此,您可能需要在return語句之前移動函數調用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM