1

I'm making a text adventure game in Python 3.4, here is the code:

class Player:
def __int__(self, name):
    self.name = name
    self.maxhealth = 50
    self.health = self.maxhealth
    self.attack = 7

def main():
    print('1. Start')
    print('2. Load')
    print('3. Exit')
    option = input('--> ')
    if option == '1':
        start()
    elif option == '2':
        pass
    elif option == '3':
        sys.exit()
    else:
        main()

def start():
    print('Hello adventurer! What is your name?')
    option = input('--> ')
    global PlayerIG
    PlayerIG = Player(option)
    start1()

def start1():
    print ('Name:',PlayerIG)
    print ('Attack:',PlayerIG.attack)

main()

I keep getting this error everytime I run my code:

PlayerIG = Player(option)
TypeError: object() takes no parameters

I can't really wrap my head around it, please help. I want to know what I did wrong in assigning the variable from a class.

6
  • 4
    Change __int__ to __init__. Commented Oct 21, 2018 at 7:05
  • Thank youuu. But now the output looks like this: Name: <__main__.Player object at 0x000000000436E240> Attack: 7. How can I fix this? Commented Oct 21, 2018 at 7:30
  • 1
    If you want to print the name of the player, why don't you print the name of the player? print('Name:', PlayerIG.name) Commented Oct 21, 2018 at 7:31
  • Oh yeah, forgot about that lol. Thank you, I'm still a beginner so this helps me a lot. Commented Oct 21, 2018 at 7:34
  • Main shouldn’t call itself. Use a while loop. Commented Oct 21, 2018 at 7:40

1 Answer 1

1

You Have to 1. change the __int__ to __init__ and indent the __init__ 2. When printing player name do PlayerIG.name.

Below is the correct code.

class Player:
      def __init__(self, name):
        self.name = name
        self.maxhealth = 50
        self.health = self.maxhealth
        self.attack = 7

def main():
        print('1. Start')
        print('2. Load')
        print('3. Exit')
        option = input('--> ')
        if option == '1':
            start()
        elif option == '2':
            pass
        elif option == '3':
            sys.exit()
        else:
            main()

def start():
        print('Hello adventurer! What is your name?')
        option = input('--> ')
        global PlayerIG
        PlayerIG = Player(option)
        start1()

def start1():
        print ('Name:',PlayerIG.name)
        print ('Attack:',PlayerIG.attack)

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

1 Comment

Thank you. I was compiling different info from youtube tutorials and pdfs that I got really confused on what to do, this helps a lot.

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.