Hello, could someone give me a hand please with my code? What happens is the following, the code works, I attack and kill the first enemy but the second enemy does not attack it, what is wrong with my code? Could someone help me please … I’m stuck on this …
javascript code:
// Collect exactly 7 spinach potions.
// Then you'll be strong enough to defeat the ogres.
var potionCount = 0;
// Wrap the potion collection code inside a while loop.
// Use a condition to check the potionCount
while(potionCount < 7) {
var item = hero.findNearestItem();
if (item) {
hero.moveXY(item.pos.x, item.pos.y);
potionCount++;
}
}
// When the while loop is finished,
// Go and fight!
var enemy = hero.findNearestEnemy();
while(enemy) {
if ( hero.isReady("stomp") ) {
hero.stomp();
}
else if (enemy) {
hero.attack(enemy);
if (enemy) {
hero.attack(enemy);
}
}
}