Power Points JS need help =)


#1

I get weird error, look like I’m doing everything right.
I can’t go to pos.x pos.y - it’s undefined

// You need to find and destroy 3 skeletons.
// Skeletons and items are summoned at points of power.
// Move to a point and say the spell: "VENI".
// To find the required points, use the wizards map.
// 0s are bad points. Positive numbers are good.

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 its a positive number:
        if (pointValue>0){
           
            // Use convert to get XY coordinates.
            var pos = convert(i, j);
            hero.say(pos);

            // Move there, say "VENI" and be prepared!

            hero.move(pos);
            hero.say(spell);
            while(true) {
                var enemy = hero.findNearestEnemy();
                if (enemy){
                    hero.attack(enemy);
                    }
                }
        }
    }
}

#2

You have a bug which helped me to find a bug in the level :slight_smile:

move is non-blocking command and as the result you are moving only one frame then your hero trying to say a spell. Try to change it to moveXY.

I fixed the bug about gridMap error. Thanks!


#3

so sorry, still stuck


#4

figured out METODOM TЫКА

var point = convert(i, j);
hero.moveXY(point.x, point.y);

not

hero.moveXY(point.pos.x, point.pos.y);

#5

Yep, because it’s “coordinates” like pos. The convert function returns pos like object.


#6

convert source is in your code, you don’t need that Metod :wink: Just look at the code.


#7

you can use flag to try where the enemy is .


#8

Thanks! I need to restrict flags there :slight_smile:


#9

you are welcome …