I’m creating a text based adventure game. The character is navigating a map made up of city blocks. I have a direction_function that takes raw_input and then moves the character to the correct adjacent block. However, I have special features, like items to pick up or people to interact with on most blocks. Here I use raw_input as well. If they enter the right keyword they interact, but if they ignore them by entering a direction, it passes them into the direction_function which prompts them for raw_input again. Is there a way to pass their initial answer into the direction_function so they don’t have to repeat their answer?
here’s my direction_function:
def direction_function(left, right, up, down, re):
direc = raw_input(">")
if direc in west:
left()
elif direc in east:
right()
elif direc in north:
up()
elif direc in south:
down()
elif direc in inventory_list:
inventory_check()
re()
else:
print "try again"
re()
I designate a function for each block like this
def block3_0():
print "You see a bike lying in your neighbor's yard. Not much else of interest."
direc = raw_input(">")
if direc in ("take bike", "steal bike", "ride bike", "borrow bike", "use bike"):
print "\n"
bike.remove("bike")
school_route()
else:
direction_function(block2_0, block4_0, block3_1, block3_0, block3_0)
Well, you can use a default argument value on your
direction_functionto pass the result of an eventual previous call toraw_input, such as:If no direction is provided (regular workflow), the test will end up calling
raw_inputto get some. If a direction is provided (like the one you’ll pass if you already read one), it will directly be used.