Icy Member
Posts : 7 Join date : 2011-06-21
| Subject: Problem w/ text adventure Thu Jun 23, 2011 5:44 am | |
| 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: - Code:
-
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('> '))
|
|
Jerremy Member
Posts : 2 Join date : 2011-06-21
| Subject: Re: Problem w/ text adventure Thu Jun 23, 2011 5:45 am | |
| Instead of using all "ifs", use "if" then "elif", and an "else". Like: - Code:
-
# ...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.
else: # This fires off if the command isn't something that we accept. print location[0] commandinput = raw_input("> ")
|
|