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

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 Likes

so sorry, still stuck

1 Like

figured out METODOM TЫКА

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

not

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

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

1 Like

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

1 Like

you can use flag to try where the enemy is .

2 Likes

Thanks! I need to restrict flags there :slight_smile:

1 Like

you are welcome …

I do not know what I am doing wrong can you please help me. It is not picking up the items or attacking the enemies and I do not know what is going on. This is my code:

// 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 wizard’s 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.
var item = hero.findNearest(hero.findItems());
var enemy = hero.findNearest(hero.findEnemies());
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:
var pos = convert(i, j);
if (pointValue > 0 && pointValue % 1===0) {
hero.moveXY(pos.x, pos.y);
hero.say(spell);
if (enemy) {
hero.attack(enemy);
}
if (item) {
hero.moveXY(item.pos.x, item.pos.y);
}

    }
    // Use convert to get XY coordinates.
    // Move there, say "VENI" and be prepared!
}

}

sorry for the not indenting

Please learn to post your code properly. It’s really easy and only requires a very small amount of effort.

To post your code from the game, use the </> button or it won’t format properly. When you click the </> button, the following will appear:

Please paste ALL of your code inside the triple back tick marks.

``` <— Triple back tick marks.

Paste ALL of your code in here.

``` <— Triple back tick marks.

There are many people here willing and able to help. If you use the </> button correctly, then ALL of your code should look like this:

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
    else:
        hero.say("My code is formatted properly")

If ALL of your code isn’t formatted like the code above, then you’re doing it wrong and we can’t see the structure of the code to troubleshoot whether or not that is the issue. Use the </> button and help us help you. This works when sending a private message as well.

Thank you.

My hero and everything else keeps freezing and I do not know what to do. Please help me. My code is bellow.

// 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 wizard's 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.
var item = hero.findNearest(hero.findItems());
var enemy = hero.findNearest(hero.findEnemies());
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:
        var pos = convert(i, j);
        if (pointValue > 0 && pointValue % 1===0) {
            hero.moveXY(pos.x, pos.y);
            hero.say(spell);
            if (enemy) {
                hero.attack(enemy);
            }    
            if (item) {
                hero.moveXY(item.pos.x, item.pos.y);
            }
            
        }
        // Use convert to get XY coordinates.
        // Move there, say "VENI" and be prepared!
    }
}



You are not using the right iterator,
and not the correct dimension in the array:

for (var j = 0; j < powerMap[i].length; j++) {

Edit:Actually this part is good im wrong lol

Also just curious:

pointValue % 1===0

When this is false?

Ohhhh… Thank you. :grin::grin::grin: