2013-12-18 60 views
0

我有一个函数作为教程游戏的一部分。如果条件满足(如果对象==“代码”),则有问题的功能应触发另一功能函数不调用另一个函数

# 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似乎完成脚本并退出。

+4

您在调用该函数之前使用'return' ...返回后的任何内容都未执行 – Jeribo

+1

'next'是python中的内置函数。你可能会考虑将你的变量重命名为别的东西('next_'是一个可行的选择) – SethMMorton

回答

2

Python中的return语句(以及几乎所有的语言 - Haskell的显着例外 - )意味着函数应在处停止。如果语句是return expr那么表达式的值可供调用者使用。否则,在Python中,调用者可以使用值None

因此,您可能需要在return语句之前移动函数调用。

+0

谢谢,已经对它进行了排序。当定时器关闭时接受 –