View Full Version : Problem w/ text adventure

03-16-2011, 12:00 PM
I am making a simple text adventure and my main problem is that whenever I type in a response it either responds correctly or with location[0] (which is the kitchen in this case). I was wondering how to correctly set out the code so that it functions correctly by stating the location[0] and then responding.

Here is the games source:

item = ('...', 'sword','emerald')
kitchen = ('Kitchen','A small room with a stove and cupboard. There is a single door to the north.', item[2], item[0], item[0])
bathroom = ('Bathroom','An old smelly room with with a sink, bath and a variety of rats and spiders. To the south there is a single door.', item[0], item[0], item[0])

room_options = {
kitchen: (bathroom,),
bathroom: (kitchen,),

command = ('help', 'items', 'take', 'drop', 'inventory', 'look', 'go')
directions = ('north', 'south', 'east', 'west')

location = kitchen

while True:
print location[0]
commandinput = raw_input('> ')

if commandinput == command[0]:
print 'Commands'
print 'Help, items, take, drop, inventory, look, go'
commandinput = (raw_input('> '))

if commandinput == command[1]:
print 'There is a:'
print location[2]
print location[3]
print location[4]
commandinput = (raw_input('> '))

if commandinput == command[2] + ' ' + location[2]:
print 'You take a ' + location[2]
commandinput = (raw_input('> '))
if location[2] == item[0]:
print 'You cant take nothing.'
commandinput = (raw_input('> '))

if commandinput == command[2] + ' ' + location[3]:
if location[3] == item[0]:
'You cant take nothing.'
commandinput = (raw_input('> '))

06-18-2011, 03:54 PM
Instead of using all "ifs", use "if" then "elif", and an "else". Like:

# ...all the code before the while
while True:
if commandinput == command[0]:
# whatever's supposed to be here.

elif commandinput == command[1]:
# keep repeating this for all other recognised commands
# and combinations.

# This fires off if the command isn't something that we accept.
print location[0]
commandinput = raw_input("> ")