0

I am using a class in python (I am also using pygame in this program) but it will not allow me to call this particular method. The class is called 'enemy'. This is the problem method:

    def attack(self, screen):
    self.charx = self.screen.get_width()/2 - self.pic.get_width()/2
    self.chary = self.screen.get_height()/2 - self.pic.get_height()/2
    textbox(self.screen, self.charx - self.c.rect.x + self.rect.x, self.chary - self.c.rect.y + self.rect.y, 15, 5, True, (255, 255, 255), True, (0, 0, 0), 0, '', True, (255, 0, 0), 15*self.healthpercent)

    if self.rect.colliderect(self.w.rect):
        if self.agility*random.randint(1, 10) > self.c.agility*random.randint(1, 10):
            self.c.health -= self.level*5  
        if self.agility*random.randint(1, 10) <= self.c.agility*random.randint(1, 10):
            self.health -= self.w.weaponpower*self.c.strength
            self.healthpercent = self.health/self.level*100

    if self.health == 0:
        self.dead = True

This is how I am calling it:

    e = enemy(enemypics, 50, 50, 4, 3, screen, c, bgdict, w)
    if e.dead == False:
        e.attack(screen) #stops on this line 
        e.update(screen)
    else:
        e.die(screen, timesincelasttick)

Obviously some variable names etc are defined elsewhere, but I didn't think those bits were necessary. This is the full stack trace:

    Traceback (most recent call last):
    File "E:\Code\Game\Main6.py", line 119, in <module>
        e.attack(screen)
    TypeError: 'int' object is not callable
    >>>
2
  • 4
    If you are getting an error, post the full stack trace Commented Feb 6, 2017 at 19:38
  • 1
    Your indentation is incorrect. Commented Feb 6, 2017 at 19:45

2 Answers 2

3

Most probable cause of this error is that somewhere else in your program you have a variable named attack and you have assigned an int value to it.

So when you do

e.attack(screen)

you are trying to call a function on that int variable attack

Make sure you don't have a variable named attack somewhere else in your program

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

Comments

0

I have solved it! I was accidentally reusing 'attack', changing it and making it an int object. I have renamed the 'attack' variable and it now works.

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.