Script killing performance

this script in my game

import GameLogic as g
cont = g.getCurrentController()
own = cont.getOwner()
Ray = cont.getSensor("Ray")[0]
shoot = cont.getActuator("shoot")[0]
obj = Ray.getHitObject()
if obj:
    if own.Time >= 4:
        obj.Health -= 2
        obj.armor -= 1
        own.Time = 0

the script works fine it just generates an error so it slows my game

It would be a lot easier if you posted the error.

o sorry how stupid of me the error is

Traceback <most recent call last>:
   File "AIray", line 13, in ?
AttributeError: Health

The hit object apparently doesn’t have a health property. One simple fix would be:

if hasattr(obj,"Health"):
   obj.Health = whatever

You might want to do all your changes in that block, because if it has a health property, it probably has the others.

“health” is not the same as “Health” you know better than that fireside ;).

Ooops. I didn’t read it that close.
Normally properties aren’t capitalized as a convention jat. That’s saved for classes and a few other things. At least the first word of a property. Something like enemyHealth is often done. I know, whoever used the Text property for text planes broke convention.

o thanks works perfectly o what does “hasattr” mean

“Has Attribute” It checks to see if the object has the given property. It returns true if it does, false if it does not.

Edit: fireside, you’re right about naming conventions. Normally first letters of properties and functions are not capitalized. Not everyone follows/knows the conventions, though.