Matt
Matt

Reputation: 69

NameError: global name 'object' is not defined Python

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

Upvotes: 2

Views: 2796

Answers (1)

eugenioy
eugenioy

Reputation: 12403

There's this line in your code:

room1 == raw_input(">")

Did you mean this?

room1 = raw_input(">")

Upvotes: 1

Related Questions