I am sorry, I had a thread similar to this, but I have encountered a different bug.

def rm_b(acts):
    print("DINING ROOM")
    print(descriptions.dining)
    acts={"north":no_exit,
          "east":rm_c,
          "south":rm_e,
          "west":rm_a,
          "sandwich":'inv_add(sandwich, acts)'}
    prompt(acts)

The "sandwich":'inv_add(sandwich, acts)' will not work. Same for all of the items I wish to allow the player to pick up. My prompt goes like this:

def prompt(acts):
    message = input(':').lower()
    print()
    try:
        if message[0:4] != 'take':
            acts[message](acts)
        elif message[0:4] = 'take':
            eval(acts[message[5:]])
    except:
        no_exit(acts)
        print()

The inv_add:

def inv_add(item, acts):
    test(" in inv_add")
    inventory.append(descriptions.item)
    print("You take:"+item)
    prompt(acts)

And the descriptions module:

sandwich = ['Sandwich', "A delicious treat."]

I would like to know why it isn't working.

Thank you for reading my post.

Recommended Answers

All 2 Replies

try commenting out the try.. except block.

Don't use try except unless absolutely necessary, it might hide a bug.

Also.. I've said this a million times.. don't hard code your instructions. It just gets tedious later.

try commenting out the try.. except block.

Don't use try except unless absolutely necessary, it might hide a bug.

Also.. I've said this a million times.. don't hard code your instructions. It just gets tedious later.

On the contrary: Using try/except blocks is the Python way (tm) if you expect that the except block will handle only (ahem) exceptional conditions. The mnemonic is "It is better to ask for forgiveness than permission." However this particular except block is indeed not a good one, and it will indeed make debugging difficult. A proper except block tells you something. I believe OP is using Python3, so a better one looks like:

try:
  None[0] # anything that might throw an Exception
except Exception as x:
  print("Drat! Type is",type(x),"Message is",x)

Of course an even better one might log the problem, set/reset some data and print a soothing message to the user...

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.