Power Points Help


#1

Hello all.

My hero only attacks the skeletons once, which is fine until she gets to the last skeleton. She hits him one and just stands there as the skeleton attacks

var spell = "VENI";
// The map of points is a 2D array of numbers.
var wizard = hero.findNearest(hero.findFriends());
var powerMap = wizard.powerMap;

// This function converts grid into x-y coordinates.
function convert(row, col) {
    return {x: 16 + col * 12, y: 16 + row * 12};
}

// Loop through the powerMap to find positive numbers.
// First, loop through indexes of rows.
for (var i = 0; i < powerMap.length; i++) {
    // Each row is an array. Iterate through it.
    for (var j = 0; j < powerMap[i].length; j++) {
        // Get the value of the i row and j column.
        var pointValue = powerMap[i][j];
        // If it's a positive number:
        if (pointValue > 0){
            // Use convert to get XY coordinates.
          var coords =  convert(i,j);
            // Move there, say "VENI" and be prepared!
            hero.moveXY(coords.x,coords.y);
            hero.say(spell);

 var enemy = hero.findNearest(hero.findEnemies());
  var item = hero.findNearest(hero.findItems());
            if(enemy){
                if(enemy.health > 0){
                hero.attack(enemy);
                }
            }
             else if (item){
                
                    hero.moveXY(item.pos.x,item.pos.y);
                    }
            }

                }
}
  

#2

use while enemy.health > 0: hero.attack(enemy) instead of the if loop