So, I've started writing a text adventure in Python, and already have the first map idea figured out, but I don't know where to start with defining a variable for each room. I know about the simple stuff, such as (represented as it would be in IDLE)

>>x = 4
>>x+1
5

but have tried searching for defining a variable for more than one line. In my case, I'm trying to define a room (with the name room1 ) with

print "You are standing in a restroom.  There is a doorway to the north, the east, west, and south walls have human-sized hole blown in them."

I was trying to get this, and the best I can think of based on my research is

room1 = {print "YYou are standing in a restroom.  There is a doorway to the north, the east, west, and south walls have human-sized hole blown in them."

, but as all of my educated guesses so far have gone, I was wrong. I'd post the rest of the code I've got written, but it's just an automated printing of the story.

You're going to want to read up on what objects are; the whole OOP thing. You'd be doing something like:

class Room(object):
    def __init__(self, description):
        self.desc = description
    def showDesc(self):
        print self.desc

myroom = Room('You are standing in a restroom...')
otherroom = Room("You are out in a dark hallway...')

# myroom.showDesc()
# etc.

You're definitely going to need to read up on all this, along with inheritance, and so forth. You can start here with Dive Into Python's "Object" section. And here's the Python documentation on classes. This is definitely an essential thing to know about.

Thanks. I'm so new that I don't really know what anything is as far as programming goes, so I get stuck. Thank you a lot. I'm off to read about this stuff and puzzle it out, now that I know what I'm looking for.

For the somewhat simple program you are writing, you don't need class objects. Those things are not too enjoyable for beginners. With Java you would be stuck with them, but Python offers you the freedom to do procedural programming too. Each room would get one name/identifier like this:

room1 = """\
You are standing in a restroom.  There is a doorway to the north, 
the east, west, and south walls have human-sized holes blown into them.
"""

# display the room description for room1
print(room1)

You can set up descriptions for room2, room3 and so on.

This article has been dead for over six months. Start a new discussion instead.