0
我正在开发一款游戏,并且卡住了钥匙应该解锁房间门的部分。现在,经过一番搜索之后,我发现我无法将一个函数中存在的变量调用到另一个函数中:正如我一直试图通过在厨房函数的条件下设置key_picked = True
一样。然后,使用房间函数中的条件,并使用布尔表达式中的key_picked
。如何将变量从另一个函数调用到另一个函数中
那么,我该如何解决这个问题?
def kitchen(already_there=False):
if choice02_key == "pick key" or choice02_key == "0" or choice02_key == "key":
print("---------------------------------------------------------")
print "You picked the key. It probably unlocks some door."
key_picked = True
kitchen(already_there=True)
def room01(already_there=False):
if key_pick == True:
print("---------------------------------------------------------")
print "You unlocked the room using the key."
else:
print "This room is locked."
entrance_hall(already_there=True)
这是一个很大的代码!如何把它煮成几行的例子。只是简单地展示问题。 – tdelaney
听起来不错。我将编辑它 –
将变量传递给函数?这个问题并不完全清楚。 –