Medical Attention - Help Needed


#1

I am working on the level Medical Attention but something has come up. In the beginning of the scene I get healed but then not once again. Here is my code:

loop:
currentHealth = self.health
healingThreshold = self.maxHealth / 2
enemy = self.findNearestEnemy()
if currentHealth < 100:
    if self.distanceTo(enemy) > 20:
        self.moveXY(65, 46)
    self.say("heal me")
   else:
    if enemy:
        if self.isReady("cleave"):
            if self.distanceTo(enemy) < 6:
                self.cleave(enemy)
            else:
                self.attack(enemy)
        else:
            self.attack(enemy)
    else:
        self.moveXY(45, 34)

I’m no sure where I’ve messed up so any help is appriciated :smile: thanks


#2

Your code needs to be one indentation level farther than your loop. Right now, since it’s at the same level, it will only do your code once.


#3

In the actually coding in the game it Shows as:

loop:
    currentHealth = self.health
    healingThreshold = self.maxHealth / 2
    enemy = self.findNearestEnemy()
    if currentHealth < 100:

Is that correct?


#4

Why do you have it as a requirement that the enemy has to be more than 20 meters away before going to heal? That may be the problem.

As a side note, you can replace

else:
    if enemy:
        #code

with

elif enemy:
    #code