Medical Attention level


#1

loop:
currentHealth = self.health
healingThreshold = self.maxHealth / 2
# If your current health is less than the threshold,
if self.health < healingThreshold:
self.moveXY(85, 46)
self.say(“heal me”)
# move to the healing point and say, “heal me”.
else:
self.attack(self.findNearestEnemy())
It keeps saying that "Target is null. Is there always an enemy to attack?(Use if)"
Can someone tell me how to fix it? Thanks


#2

To format your code correctly, please highlight it and click the </> button. Reading the FAQ first helps. :wink:

That error message, in my experience, usually means that you should change [quote=“DiamondsGaming, post:1, topic:6145”]
self.attack(self.findNearestEnemy())
[/quote]to something like this:

enemy = self.findNearestEnemy()
if enemy:
    self.attack(enemy)

This keeps your hero from trying to attack an enemy that doesn’t exist.