Power Points JS need help =)


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);

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

            while(true) {
                var enemy = hero.findNearestEnemy();
                if (enemy){


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!


so sorry, still stuck


figured out METODOM TЫКА

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


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


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


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


you can use flag to try where the enemy is .


Thanks! I need to restrict flags there :slight_smile:


you are welcome …