Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7998421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:12:32+00:00 2026-06-04T15:12:32+00:00

I get this error during a lengthy match in my strategy game, Table Wars.

  • 0

I get this error during a lengthy match in my strategy game, Table Wars. It seems to occur whenever there are many units on the battlefield. Here is the traceback:

Traceback (most recent call last):
  File "C:\Users\Oventoaster\Desktop\Games\Table Wars\Table Wars.py", line 727, in <module>
    main()
  File "C:\Users\Oventoaster\Desktop\Games\Table Wars\Table Wars.py", line 131, in main
RedTeam.update()
  File "C:\Python27\lib\site-packages\pygame\sprite.py", line 399, in update
for s in self.sprites(): s.update(*args)
  File "C:\Users\Oventoaster\Desktop\Games\Table Wars\Table Wars.py", line 372, in update
self.attack()
  File "C:\Users\Oventoaster\Desktop\Games\Table Wars\Table Wars.py", line 393, in attack
    self.target.health -= self.attack_damage
AttributeError: 'NoneType' object has no attribute 'health'

The exception seems to appear in the targeting and attacking codes, so I will post them here:

def move_toward(self, target):
    if self.target is None:
        self.rect.move_ip(1, 0)

def update(self):
    self.find_target()
    self.move_toward(self.target)
    self.attack()
    if self.health <= 0:
        self.kill()

def find_target(self):
    if self.target is not None: return
    for enemy in BluTeam.sprites():
        if enemy.rect.centerx - self.rect.centerx <= self.range and enemy.rect.centery - self.rect.centery <= self.range:
            self.target = enemy
            return
        self.target = None

def attack(self):
    global REDGOLD
    global BLUECOMMAND
    if self.target is None: return
    if self.target.health <= 0:
        REDGOLD += self.target.reward
        BLUECOMMAND += self.target.cmdback
        self.target = None
    if not self.cooldown_ready(): return
    self.target.health -= self.attack_damage

def cooldown_ready(self):
    now = pygame.time.get_ticks()
    if now - self.attack_last >= self.attack_cooldown:
        self.attack_last = now
        return True
    return False

How do I fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:12:34+00:00Added an answer on June 4, 2026 at 3:12 pm

    Explanation of a common error or how to better understand a simple traceback to debug my program:

      File "<path>\<filename>.py", line 393, in <function>
    

    Traceback gives you the callstack and points to the error raises in which function. Nothin special here

        self.target.health -= self.attack_damage
    

    Friendly interpreter gives the statement causing the error. This is important as it means the error raised is related to this line of code.

    AttributeError: 'NoneType' object has no attribute 'health'
    

    Here we are. The error is AttributeError ; the doc is pretty clear about it: I’m trying to read the value of or I’m trying to assign to a variable that is not a member of the related object.

    What is my object ? It is a 'NoneType' object ; we don’t have the name, but we have its type. The object we have an issue with is NoneType, thus it is the special object None.

    What is the error with this Noneobject ? It doesn’t have a 'health' attribute is saying the Traceback. So, we are accessing the attribute health somewhere in the line of code the error raises, and this is called on a None object.

    Now we are almost all set: self.target.health is the only location in the error line we use health, thus it means self.target is None. Now I look at the source code I try to understand why it could be, even if I put a check at the beginning at the function against it. It leads to the fact I must set it to None somehow after that line.


    All of this reasoning steps lead to the short answer:

    It means self.target is None. The error comes from your code:

    if self.target.health <= 0:
        REDGOLD += self.target.reward
        BLUECOMMAND += self.target.cmdback
        self.target = None  # set to None
    if not self.cooldown_ready(): return
    self.target.health -= self.attack_damage  # self.target is None, .health failed
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cannot figure out why I get this error during check-in. I checked in
what is wrong about the following code? I get this error during compilation: The
It says (note this is during run-time I get this error)... I have no
during build with Visual Studio C++ I get this error: error C2027: use of
Sometimes I get this strange error during gameplay: TypeError: Error #1009: Cannot access a
I get this 'error' when running PEVerify on a custom generated assembly. [MD](0x8013124C): Error:
I get this error when trying ruby script/console Rails requires RubyGems >= . Please
I get this error message in Eclipse: Access restriction: The type DirectoryWalker is not
I get this error when I run a django app ( dpaste ) Template
I get this error when I try to use time_ago_in_words : Comparison of String

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.