Ok,
So I'm working on a simple text rpg (in Python) currently. But for some reason, one of my functions is reading inputs weird.
Right now, each room in the dungeon is a separate function. Here is the room that isn't working:
def strange_room():
global fsm
global sword
global saw
if not fsm:
if not saw:
print "???..."
print "You're in an empty room with doors on all sides."
print "Theres a leak in the center of the ceiling... strange."
print "In the corner of the room, there is an old circular saw blade leaning against the wall."
print "What do you want to do?"
next6 = raw_input("> ")
print "next6 = ", next6
if "left" in next6:
zeus_room()
elif "right" in next6:
hydra_room()
elif "front" or "forward" in next6:
crypt_room()
elif ("back" or "backwad" or "behind") in next6:
start()
elif "saw" in next6:
print "gothere"
saw = True
print "Got saw."
print "saw = ", saw
strange_room()
else:
print "What was that?"
strange_room()
if saw:
print "???..."
print "You're in an empty room with doors on all sides."
print "Theres a leak in the center of the ceiling... strange."
print "What do you want to do?"
next7 = raw_input("> ")
if "left" in next7:
zeus_room()
elif "right" in next7:
hydra_room()
elif "front" or "forward" in next7:
crypt_room()
elif ("back" or "backwad" or "behind") in next7:
start()
else:
print "What was that?"
strange_room()
My issue is with getting my input. This function executes up until line 17. It seems to take an input the first time around, but the print statement to print the input doesn't execute. Then, on top of that, only the left, right, and front/forward commands work correctly. Anything else I type in only executes the crypt_room() function that "front"/"forward" should execute.
Thanks.
The expression
"front" or "forward" in next6
evaluates to "front"
and is always considered true in an if
statement. What you probably mean is
"front" in next6 or "forward" in next6
There are more mistakes of this type in your code. In general, the expression
A or B
evaluates to A
if A
is truthy and to B
otherwise.
As a side note, the whole design of your program is broken. The recursive calls when entering different rooms will quickly hit the maximum recursion depth.