0

I'm working on a text based escape the room game. I've finished it but whenever i enter the command 'help' or most any other, the command executes and does what it's meant to but instead of returning to where it was before the command, the game has an error and dies. Some pointers please?


Not sure how to include the text as-is so i just attached it as a .txt

Attachments
#!/usr/bin/python.py
# Filename: MannerBold.py
import time
global gold
gold=0
def start():
    print ("You open your eyes and find yourself in what looks to be the entry\
            of a grand house")
    print ("You have no memories of the previous day and how you came to be here.")
    print ("When you look around the Grand Hall you find the front door.")
    print ("The front door is locked and chains stretch from side to side of the door.")
    print ("When you approach the front door a little man appears before the door.")
    print ("When you meet his gaze words rough and harsh form in your mind:")
    time.sleep(13)
    print ("PASSAGE THROUGH MY GATES IS HIGH")
    time.sleep(3)
    print ("MANY FOR MY ATTENTION DO VYE")
    time.sleep(3)
    print ("TO ESCAPE MY MANNER BOLD")
    time.sleep(3)
    print ("MY HANDS MUST HOLD")
    time.sleep(3)
    print ("FOUR COINS OF GOLD.")
    ghall()
def ghall():
    time.sleep(2)
    print ("Current Gold Coins == ",gold)
    time.sleep(2)
    print ("You are in the Grand Hall.")
    print ("From the ceiling hangs a monster of a chandaler.")
    print ("The walls of the Grand Hall are of an old, dark wood.")
    print ("The front doors are to the south.")
    print ("To the East and West are doors.")
    print ("Next to the door to the West is a large table.")
    print ("On the table are all manner of things.")
    print ("Type 'help' for help")
    prompt_ghall()
def prompt_ghall():
    print ("You are in the Grand Hall")
    prompt_ghall = input("Enter command: ")
    if prompt_ghall == "W":
        lab()
    elif prompt_ghall == "w":
        lab()
    elif prompt_ghall == "West":
        lab()
    elif prompt_ghall == "west":
        lab()
    elif prompt_ghall == "E":
        kitchen()
    elif prompt_ghall == "e":
        kitchen()
    elif prompt_ghall == "East":
        kitchen()
    elif prompt_ghall == "east":
        kitchen()
    elif prompt_ghall == "help":
        print ("'examine (object)...North, East, West, South...Take (item)\
                CASE SENSITIVE!!")
        prompt_ghall()
    elif prompt_ghall == "examine table":
        print ("The table is covered with old, yellowed documents. Nothing of \
                Interest is here.")
        prompt_ghall()
    elif prompt_ghall == "S":
        if gold < 4:
            print ("The front doors won't open until you have 4 gold coins.")
            prompt_ghall()
    elif prompt_ghall == "s":
        if gold < 4:
            print ("The front doors won't open until you have 4 gold coins.")
            prompt_ghall()
    elif prompt_ghall == "South":
        if gold < 4:
            print ("The front doors won't open until you have 4 gold coins.")
            prompt_ghall()
    elif prompt_ghall == "south":
        if gold < 4:
            print ("The front doors won't open until you have 4 gold coins.")
            prompt_ghall()
def lab():
    print ("Current Gold = ",gold)
    time.sleep(2)
    print ("You move into the Lab. When you enter the Lab you find that the \
            ceiling is uncomfterably low. From the center of the room to the \
            north and south walls stretches two long and wide tables. On the \
            tables are many bottles and vials of many colors. Along the walls \
            of the Lab are bookshelves overflowing with books of varying sizes \
            and colors. \
            Exits are to the East and North.\
            type 'help' for help")
    prompt_lab()
def prompt_lab():
    prompt_lab = input("Enter command: ")
    if prompt_lab == "E":
        ghall()
    elif prompt_lab == "e":
        ghall()
    elif prompt_lab == "East":
        ghall()
    elif prompt_lab == "east":
        ghall()
    elif prompt_lab == "N":
        armory()
    elif prompt_lab == "n":
        armory()
    elif prompt_lab == "North":
        armory()
    elif prompt_lab == "north":
        armory()
    elif prompt_lab == "help":
        print ("examine (object)...N, E, W, S...take (item)")
        prompt_lab()
    elif prompt_lab == "examine table":
        print ("Burried under the treasures on the table is one gold coin.")
        prompt_lab()
    elif prompt_lab == "take gold coin":
        print ("You receive 1 gold coin")
        gold = gold+1
        lab()
def armory():
    print ("Current gold = ",gold)
    time.sleep(2)
    print ("You move into the Armory. All around you on the walls are mounted \
            suits of armour complete with weapons and fresh coats of oil. Between \
            each suit of armour are racks of weapons, ranging from simple daggers \
            and swords to flails, crossbows and poisoners' knives. The center \
            of the room is sunken into the floor with a diagram of a land you do not \
            recognize. \
            There are exits to the South and East.\
            Type 'help' for help")
    prompt_armory()
def prompt_armory():
    prompt_armory = input("Enter command: ")
    if prompt_armory == "S":
        lab()
    elif prompt_armory == "s":
        lab()
    elif prompt_armory == "South":
        lab()
    elif prompt_armory == "south":
        lab()
    elif prompt_armory == "help":
        print ("examine (object)...N, E, W, S...take (item)")
        prompt_armory()
    elif prompt_armory == "examine armour":
        print ("The suits are spotless and shiney beyond belief but useless to you.")
        prompt_armory()
    elif prompt_armory == "examine diagram":
        print ("The diagram is of an unknown land to you and as such, useless.")
        prompt_armory()
    elif prompt_armory == "examine weapon racks":
        print ("The amound of different weapons is awe inspiring. Burried in \
                the chains of a flail is a gold coin.")
        prompt_armory()
    elif prompt_armory == "take gold coin":
        print ("You receive 1 gold coin.")
        gold = gold+1
        prompt_armory()
    elif prompt_armory == "E":
        hall()
    elif prompt_armory == "e":
        hall()
    elif prompt_armory == "East":
        hall()
    elif prompt_armory == "east":
        hall()
def hall():
    print ("Current gold = ",gold)
    time.sleep(2)
    print ("You are in a tiny hall with doors to the East, South and West. \
            The floor of the hall is coated in a heavy layer of dust. \
            Type 'help' for help.")
    prompt_hall()
def prompt_hall():
    prompt_hall = input("Enter command: ")
    if prompt_hall == "W":
        armory()
    elif prompt_hall == "w":
        armory()
    elif prompt_hall == "West":
        armory()
    elif prompt_hall == "west":
        armory()
    elif prompt_hall == "help":
        print ("examine (object)...N, E, W, S...take(item)")
        prompt_hall()
    elif prompt_hall == "S":
        ghall()
    elif prompt_hall == "s":
        ghall()
    elif prompt_hall == "South":
        ghall()
    elif prompt_hall == "south":
        ghall()
    elif prompt_hall == "E":
        library()
    elif prompt_hall == "e":
        library()
    elif prompt_hall == "East":
        library()
    elif prompt_hall == "east":
        library()
    elif prompt_hall == "examine floor":
        print ("In the NW corner burried under the durst is a gold coin.")
        prompt_hall()
    elif prompt_hall == "take gold coin":
        print ("You recieved a gold coin.")
        gold = gold+1
        prompt_hall()
def library():
    print ("Gold coins = ",gold)
    time.sleep(2)
    print ("You walk into the library. The walls of the library are covered with \
            bookshelves and the bookshelves are covered with books. The ground is \
            covered in books as well from books that have fallen from the bookshelves.\
            There are exits to the West and South.\
            Type 'help' for help.")
    prompt_library()
def prompt_library():
    prompt_library = input("Enter command: ")
    if prompt_library == "W":
        hall()
    elif prompt_library == "w":
        hall()
    elif prompt_library == "West":
        hall()
    elif prompt_library == "west":
        hall()
    elif prompt_library == "help":
        print ("examine (object)...N, E, W, S...take (object)")
        prompt_library
    elif prompt_library == "examine floor":
        print ("The floor is covered in books. Though interesting, they are useless.")
        prompt_library
    elif prompt_library == "examine bookshelves":
        print ("The bookshelves are covered in old books. There is nothing of interest.")
        prompt_library
    elif prompt_library == "S":
        kitchen()
    elif prompt_library == "s":
        kitchen()
    elif prompt_library == "South":
        kitchen()
    elif prompt_library == "south":
        kitchen()
def kitchen():
    print ("Gold coins = ",gold)
    time.sleep(2)
    print ("You enter the kitchen and find it to be of an old design. The kitchen lacks\
            any electronic appliance. It has spotless spacious counters. The icebox in \
            the corner is open slightly and the shelves and pantry are all closed and \
            locked.\
            There are exits to the North and West.\
            Type 'help' for help")
    prompt_kitchen()
def prompt_kitchen():
    prompt_kitchen = input("Enter command: ")
    if prompt_kitchen == "N":
        library()
    elif prompt_kitchen == "n":
        library()
    elif prompt_kitchen == "North":
        library()
    elif prompt_kitchen == "north":
        library()
    elif prompt_kitchen == "W":
        ghall()
    elif prompt_kitchen == "w":
        ghall()
    elif prompt_kitchen == "West":
        ghall()
    elif prompt_kitchen == "west":
        ghall()
    elif prompt_kitchen == "help":
        print ("examine (object)...N, E, W, S...take (object)")
        prompt_kitchen()
    elif prompt_kitchen == "examine counters":
        print ("The counters of the kitchen are spotless and rise to just above your waist hight.\
                They are useless
2
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by 0x69
0

Several problems here-
1. Change function input() to raw_input() . Input() expects valid python code and does evaluation of that code.
2. You are reading user command to variable 'prompt_ghall' and hence such interpreter error:

Traceback (most recent call last):
[...]
  File "Mannerbold.py", line 61, in prompt_ghall
    prompt_ghall()
TypeError: 'str' object is not callable

Change 'prompt_ghall' variable name to something different than your function 'prompt_ghall()' name.

3. Not error, but something which will make your code more readable and less redundant. Define function

def exec_action(inp, command_list, action):
    for cmd in command_list:
        if cmd==inp:
            action()
            break

then for example in prompt_ghall() function instead of long list of elif's you could write short code:

exec_action(prompt_ghall_var,["W","w","West","west"],lab)
exec_action(prompt_ghall_var,["E","e","East","east"],kitchen)

good luck.

0

Thanks.
Looks cleaner but for some reason I can't find out, there's still errors.
Says that raw_input needs to be defined...not sure how.

#!/usr/bin/python.py
# Filename: MannerBold2.py
import time
global gold
gold=0
def start():
    print ("You open your eyes and find yourself in what looks to be the entry of\
            a grand house.")
    print ("You have no memories of the previous day and how you came to be here.")
    print ("When you look around the Grand Hall you notice the front door.")
    print ("The front door is locked. Chains span the length of the wide double doors.")
    print ("When you walk south to further inspect the door a voice appears in your\
            mind, its defining characteristic being a total lack of emotion.")
    print ("The voice says: ")
    print ("PASSAGE THROUGH MY GATES IS HIGH")
    print ("TO ESCAPE THIS WORLD OF LIE")
    print ("TO ESCAPE THIS MANNER BOLD")
    print ("MY HANDS MUST HOLD")
    print ("FOUR COINS OF GOLD.")
    print ("Current Gold Coins = ",gold)
    ghall()
def ghall():
    print ("You are in the Grand Hall.")
    print ("From the ceiling hangs a monster chandaler.")
    print ("The walls of the Grand Hall are of an old, dark wood.")
    print ("The front doors are to the south.")
    print ("To the West and East are doors.")
    print ("Next to the table to the West is an large, old table.")
    print ("Type 'help' for help.")
    ghallchoice()
def ghallchoice():
    print ("You are in the Grand Hall.")
    ghallchoice = raw_input("What do you do: ")
    exec_action(ghallchoice_var,["W","w","West","west"],lab())
    exec_action(ghallchoice_var,["E","e","East","east"],kitchen())
    if ghallchoice == "help":
        print ("'examine (object)...north, east, west, south...take (object)'")
        ghallchoice()
    elif ghallchoice == "examine table":
        print ("The table is covered with old, yellowed documents. Nothing of\
                interest here.")
        ghallchoice()
    elif ghallchoice == "S":
        if gold < 4:
            print ("The front doors won't open until you have 4 gold coins.")
            ghallchoice()
        elif gold > 3:
            print ("You escape Manner Bold. Congratulations.")
            time.sleep(5)
            exit()
    elif ghallchoice == "s":
        if gold < 4:
            print ("The front doors won't open until you have 4 gold coins.")
            ghallchoice()
        elif gold > 3:
            print ("You escape Manner Bold. Congratulations.")
            time.sleep(5)
            exit()
    elif ghallchoice == "South":
        if gold < 4:
            print ("The front doors won't open until you have 4 gold coins.")
            ghallchoice()
        elif gold > 3:
            print ("You escape Manner Bold. Congratulations.")
            time.sleep(5)
            exit()
    elif ghallchoice == "south":
        if gold < 4:
            print ("The front doors won't open until you have 4 gold coins.")
            ghallchoice()
        elif gold > 3:
            print ("You escape Manner Bold. Congratulations.")
            time.sleep(5)
            exit()
def lab():
    print ("Current Gold = ",gold)
    time.sleep(2)
    print ("You move into the Lab. When you enter the Lab you find that the \
            ceiling is uncomfterably low. From the center of the room to the \
            north and south walls stretches two long and wide tables. On the \
            tables are many bottles and vials of many colors. Along the walls \
            of the Lab are bookshelves overflowing with books of varying sizes \
            and colors. \
            Exits are to the East and North.\
            type 'help' for help")
    labchoice()
def labchoice():
    labchoice = raw_input("What do you do: ")
    exec_action(labchoice_var,["N","n","North","north"],armory())
    exec_action(labchoice_var,["E","e","East","east"],ghall())
    if labchoice == "help":
        print ("examine (object)...N, E, W, S...take (item)")
        labchoice()
    elif labchoice == "examine table":
        print ("Burried under the treasures on the table is one gold coin.")
        labchoice()
    elif labchoice == "take gold coin":
        print ("You receive 1 gold coin")
        gold = gold+1
        labchoice()
def armory():
    print ("Current gold = ",gold)
    time.sleep(2)
    print ("You move into the Armory. All around you on the walls are mounted \
            suits of armour complete with weapons and fresh coats of oil. Between \
            each suit of armour are racks of weapons, ranging from simple daggers \
            and swords to flails, crossbows and poisoners' knives. The center \
            of the room is sunken into the floor with a diagram of a land you do not \
            recognize. \
            There are exits to the South and East.\
            Type 'help' for help")
    armorychoice()
def armorychoice():
    armorychoice = raw_input("What do you do: ")
    exec_action(armorychoice_var,["E","e","East","east"],hall())
    exec_action(armorychoice_var,["S","s","South","south"],lab())
    if armorychoice == "help":
        print ("examine (object)...N, E, W, S...take (object)")
        armorychoice()
    elif armorychoice == "examine armor":
        print ("The suits are spotless and shiney beyond belief but useless to you.")
        armorychoice()
    elif armorychoice == "examine armour":
        print ("The suits are spotless and shiney beyond belief but useless to you.")
        armorychoice()
    elif armorychoice == "examine diagram":
        print ("The diagram shows an unknown land. It is useless to you.")
        armorychoice()
    elif armorychoice == "examine weapon racks":
        print ("The amount of different weapons is shocking. Burried in the\
                chains of a flail is a gold coin.")
        armorychoice()
    elif armorychoice == "take gold coin":
        print ("You recieve 1 gold coin")
        gold = gold+1
        armorychoice()
def hall():
    print ("Current gold = ",gold)
    time.sleep(2)
    print ("You are in a tiny hall with doors to the East, South and West. \
            The floor of the hall is coated in a heavy layer of dust. \
            Type 'help' for help.")
    hallchoice()
def hallchoice():
    hallchoice = raw_input("What do you do: ")
    exec_action(hallchoice_var,["W","w","West","west"],armory())
    exec_action(hallchoice_var,["E","e","East","east"],library())        
    exec_action(hallchoice_var,["S","s","South","south"],ghall())
    if hallchoice == "help":
        print ("examine (object)...N, E, S. W...take (object)")
        hallchoice()
    elif hallchoice == "examine floor":
        print ("In the NW corner burried under the dust is a gold coin.")
        hallchoice()
    elif hallchoice == "take gold coin":
        print ("You recieve 1 gold coin")
        gold = gold+1
        hallchoice()
def library():
    print ("Gold coins = ",gold)
    time.sleep(2)
    print ("You walk into the library. The walls of the library are covered with \
            bookshelves and the bookshelves are covered with books. The ground is \
            covered in books as well from books that have fallen from the bookshelves.\
            There are exits to the West and South.\
            Type 'help' for help.")
    librarychoice()
def librarychoice():
    librarychoice = raw_input("What do you do: ")
    exec_action(librarychoice_var,["S","s","South","south"],kitchen())
    exec_action(librarychoice_var,["W","w","West","west"],hall())
    if librarychoice == "help":
        print ("examine (object)...N, E, W, S...take(object)")
        librarychoice()
    elif librarychoice == "examine floor":
        print ("The floor is covered in books. Though interesting, they are useless.")
        librarychoice()
    elif librarychoice == "examine bookshelves":
        print ("The bookshelves have books on them but more around them, fallen onto\
                the floor. Nothing interesting though.")
        librarychoice()
def kitchen():
    print ("Gold coins = ",gold)
    time.sleep(2)
    print ("You enter the kitchen and find it to be of an old design. The kitchen lacks\
            any electronic appliance. It has spotless spacious counters. The icebox in \
            the corner is open slightly and the shelves and pantry are all closed and \
            locked.\
            There are exits to the North and West.\
            Type 'help' for help")
    kitchenchoice()
def kitchenchoice():
    kitchenchoice = raw_input("What do you do: ")
    exec_action(kitchenchoice_var,["n","N","North","north"],library())
    exec_action(kitchenchoice_var,["W","w","West","west"],ghall())
    if kitchenchoice == "help":
        print ("examine (object)...N, E, W, S...take (object")
        kitchenchoice()
    elif kitchenchoice == "examine counters":
        print ("The counters of the kitchen are spotless and rise to just above\
                your waist. They are useless to you.")
        kitchenchoice()
    elif kitchenchoice == "examine shelves":
        print ("The shelves are locked and won't open.")
        kitchenchoice()
    elif kitchenchoice == "examine pantry":
        print ("The pantry is locked and useless to you.")
        kitchenchoice()
    elif kitchenchoice == "examine icebox":
        print ("The icebox is devoid of ice. In the bottom of the icebox is a gold coin")
        kitchenchoice()
    elif kitchenchoice == "take gold coin":
        print ("You receive 1 gold coin.")
        gold = gold+1
        kitchenchoice()
def exec_action(inp, command_list, action):
    for cmd in command_list:
        if cmd==inp:
            action()
            break
start()

No idea how to fix that

0

Arhg... Seems you are using Python 3, and I tested your script on Python 2.6.
On Python 3, input() must work like raw_input() on Python 2.6. So just restore original input() case ;)
I see you didn't fix second error like i said. Fix it- change these variable names to something different:
ghallchoice
labchoice
armorychoice
hallchoice
librarychoice
kitchenchoice
Their names coincides with function names - which is BAD. In essence you trying to assign input() result to function object.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.