1

A little while ago I decided to take on a text adventure game. I always wanted to do that. But the first time it did an epic fail. This time I'm getting closer but just not there. I think I saw the error, though: The problem is that the variable isn't carried to the next def. So the thing I want to know is how do I solve it?

This is the piece of code that describes the problem:

def start():
    print "Hello there Knight... Knight? Sir Knight, what's your name?"
    name = raw_input("> ")
    print "Well sir %s of simpleton. We have a message from the queen, do you want to read it?" % name
    rm = raw_input("> ")
    rm(rm)

def rm(rm):
    if rm ==  "yes":
        print "It says: \n Dear %s, \n Our kingdom is in great danger. Dragon Redpole has captured the beatiful princess. Who ever saves her    rom his dangerous castle may marry her." % name
        print "What will you do? Go undercover to The Far Lands or in full weaponry"
        UorW = raw_input("type u or fw \n > ")
    elif rm ==  "no":
        print "I am sorry sir, but the queen's word is la.. SHUT UP YOU USELESS PIECE OF TRASH OUT OF THIS ROOM NOW!! You say highly irritated. Will you tell the torturer to torture  the butler in the dungeons?"
        torture_butler = raw_input(">  ")    
        torture_butler()
    else: 
        print "That's not possible"

This is the report I get:

Traceback (most recent call last):
  File "story.py", line 59, in <module>
    start()
  File "story.py", line 6, in start
    rm(rm)
TypeError: 'str' object is not callable
1
  • 3
    Please fix the indentation, this code won't run as it is posted. Commented Nov 20, 2011 at 23:27

2 Answers 2

6

You overwrite the function named rm() with the return value of raw_input("> "). After this line, the name rm will point to a string object, and trying to call this string object fails because string objects aren't callable. Rename the variable so that it does not shadow the function name.

Sign up to request clarification or add additional context in comments.

Comments

1

From the way your code is written, the name rm does not refer to the function of that name in either the start function, nor the rm function. In both cases rm is a local variable which hides the function definition.

As has already been suggested in other answers, you need to avoid overloading the same name with multiple meanings.

Comments

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.