2

I have been doing Python for a couple months now, and am having trouble with defining functions. I am just creating a small CYOA maze where there are multiple rooms and the player would have to go back and forth. It works with some of the function but I am getting NameError: global name 'object' is not defined error.

#Main room
def big_room():
    print """You arrive inside a huge square room. You are presented with 
3 giant wooden doors. Which door do you choose?Or you can Leave."""


    room = raw_input(">")

    if room == "door one":
        print"You open door one and walk in."
        room_one()
    elif room == "door two":
        room_two()
    elif room == "door three":
        print """You go toward door three and attempt to pull it.
The door opens loudly and you walk in."""
        room_three()
    elif room == "Leave":
        dead("You decide to walk away and get eaten by a Jaguar")
    else:
        print "What are you saying?." 

def room_one():
    print """The room has one torch lighting the room with a faint glow. You are presented
with another three doors. Which way do you go? or go back"""


    room1 == raw_input(">")

    if room1 == "door one":
        print "Test"
    elif room1 == "door two":
        print"Test"
    elif room1 == "door c":
        hole()
    elif room1 == "go back":
        big_room()
    else:
        print "test me"

def hole():
    print "You take a step forward and the floor below you caves in; you fall in and die."
    dead()


def dead(why):
    print why,"Game over!"
    exit(0)


raw_input("Press Enter to Continue")

def start():
    print """After a long time of walking through a thick jungle,
you arrive at a temple covered in foliage and a narrow entrance.
go inside. or Leave"""

    while True:
        temple = raw_input(">")

        if temple =="go inside":
            big_room()
        elif temple == "Leave":
            dead("You decide to walk away and get eaten by a Jaguar")
        else:
            print "What are you saying?"

start()

When I run it, I can get into big_room and then I type door one to get to door_one(). I assume it's supposed to get to def room_one() and run from there. Expcept I get

The room has one torch lighting the room with a faint glow. You are presented
with another three doors. Which way do you go? or go back
Traceback (most recent call last):
  File "flee.py", line 78, in <module>
    start()
  File "flee.py", line 72, in start
    big_room()
  File "flee.py", line 21, in big_room
    room_one()
  File "flee.py", line 38, in room_one
    room1 == raw_input(">")
NameError: global name 'room1' is not defined

I was sure I would define it when I put in some input like I did in big_room(). Any help would be greatly appreciated. Thank you

2
  • FYI: Your error is in the second-to-last line of your traceback :P (One of the good things about python: most of the time, the traceback will tell you exactly what you did wrong) Commented Jul 8, 2015 at 1:00
  • You're right! Just missed it this time. I'll be looking closer! Commented Jul 8, 2015 at 1:02

1 Answer 1

1

There's this line in your code:

room1 == raw_input(">")

Did you mean this?

room1 = raw_input(">")
Sign up to request clarification or add additional context in comments.

1 Comment

I guess I did! That did it, that makes sense. I'm sure I've made that mistake before and it finally did something here. That worked after removing the other equal sign. Very fast. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.