Easy A
Would you like to react to this message? Create an account in a few clicks or log in to continue.


 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

Share
 

 Problem w/ text adventure

View previous topic View next topic Go down 
AuthorMessage
Icy
Member
Member
Icy

Posts : 7
Join date : 2011-06-21

Problem w/ text adventure Empty
PostSubject: Problem w/ text adventure   Problem w/ text adventure EmptyThu 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('> '))
Back to top Go down
Jerremy
Member
Member
Jerremy

Posts : 2
Join date : 2011-06-21

Problem w/ text adventure Empty
PostSubject: Re: Problem w/ text adventure   Problem w/ text adventure EmptyThu 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("> ")
Back to top Go down
 

Problem w/ text adventure

View previous topic View next topic Back to top 
Page 1 of 1

 Similar topics

-
» C++ Text Adventure assistance?
» text set to x number of pixels.
» Append increments of 50 to end of lines of text
» creating formattable text input script
» PC problem

Permissions in this forum:You cannot reply to topics in this forum
Easy A :: Problem w/ text adventure Edit-trash Useless :: Trash-