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

Recommended Answers

All 3 Replies

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.

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.