A hint: you can’t compare self.findNearestEnemy() to 10 with a < operator, because it returns an enemy object, not a number. You want to compare the distanceTo(enemy) with 10 with a < operator (you want to cleave if the distance is less than 10).
# If the ogres rush at you, cleave them!
# If they stay 10 meters away, attack the "Chest".
loop:
enemy =
if self.distanceTo(enemy):
self.cleave(enemy)
else:
self.attack("Chest")
if self.distanceTo(enemy): just asks whether the distance is truthy. Since distance is a number, that’ll be true whenever it’s not zero. But it’s always more than zero. You probably want to see whether the distance is less than 10 with if self.distanceTo(enemy) < 10:.
I don’t think this is how it should be done.
I’m going to assume that the everything but the loops should be intended.
This code is not correct (it is not wrong, but also not correct) because:
Your second loop will never be executed, because the first one never stops running.
You should only cleave when they are closer than 10 units.
You should not cleave unless the enemies are closer than 10 units.
Programming Style tip:
You should check if this.sReady("cleave") before cleaving.
I assume you just got the timing right with all your attacks, and it might even work, but if your enemies close in too late, you don’t catch anyone with your cleave, and if they close in too early you get damage up to a point where you die unless you have a lot of HP.
Thank you for your opinion. Unfortunately, some players have less armor than you do, and so they must utilize this strategy instead of simply attacking the chest.
Has it occurred to you that this thread is twenty days old, and Hannah has likely already solved this level and moved on? Please leave the dead resting.