# Help interception

#1

hello I am at this level interception where profit not make my hero take the same route as the peasant this is my code.

while(true) {
var enemy = hero.findNearest(hero.findEnemies());
var friend = hero.findFriends();
// Find the point between the enemy’s position and your friend’s position.
// Check the guide if you need more help!
if(enemy){
if(friend.type == “hamming-peasant”){
var x = (enemy.pos.x + friend.x)/2;
var y = (enemy.pos.y + friend.y)/2;
hero.moveXY(x, y);
}
}
}

when placing friend.type == “peasante” I leave to get out mistake as I was saying before that is not recognized NaN x, y, y = NaN

I was told that friend is a good arrangement but I’m no expert’m learning if such an arrangement might know in what position is the peasante you have to protect my hero.

although I seem more an object

#2

`hero.findFriends()` returns an array of friends, not a friend. Even if there is only one friend, then it will be the array with one element.

#3

Thank Bryukh you, I takes me truth to understand something so simple but it worked out. Thanks for your help.

while(true) {
var enemy = hero.findNearest(hero.findEnemies());
var friend = hero.findFriends();

``````if(enemy){
var x = (enemy.pos.x + friend[0].pos.x)/2;
var y = (enemy.pos.y + friend[0].pos.y)/2;
hero.moveXY(x, y);
}
``````

}

1 Like