The Code:
while True:
# Now you can patrol the village using findAndAttackEnemy
hero.moveXY(35, 34)
findAndAttackEnemy()
# Now move to the right entrance.
hero.moveXY(60, 31)
# Use findAndAttackEnemy
findAndAttackEnemy
The hero moves to the left, hits the enemy and removes half of its health, moves to the right, doesn’t even hit the enemy, then moves a little to the left before it ends.
Note the difference between using a function as a value, findAndAttackEnemy, and actually calling the function, findAndAttackEnemy(). The latter actually executes the code defined above in the function block.
Note the parenthesis.
You say your hero only removes half the health of the left enemy? Try modifying findAndAttackEnemy to attack twice (or more, if necessary).
Hi! I’m not sure if what you need to do is the same as finding and attacking an enemy, but I will give you the example anyway, for this you need to create a variable called enemy and that it has the value of finding the closest enemy, then use attack al enemy with this variable inside the parameter of that method.
//Javascript example:
var enemy = hero.findNearestEnemy();
if(enemy){
hero.attack(enemy); //Is this what you need to do?
}
With this code what you do is say “if, there is an enemy nearby then attack”.
Wow congratz!
In the same way, maybe instead of using the same one twice, maybe it is better to use a while (enemy) {findEneemyAndAttack} or something similar to loop until the enemy is killed