Cant solve WHILE OGRES WERE SLEEPING - JAVASCRIPT- please help

var points = [{x: 21, y: 8}, {x: 33, y: 8}, {x: 45, y: 8},
    {x: 57, y: 8}, {x: 68, y: 8}, {x: 68, y: 18},
    {x: 68, y: 28}, {x: 68, y: 38}, {x: 68, y: 48},
    {x: 68, y: 58}, {x: 56, y: 58}, {x: 44, y: 58}, 
    {x: 32, y: 58}, {x: 20, y: 58}, {x: 10, y: 60}];

var pointIndex = 0;

while (pointIndex < points.length) {
    var point = points[pointIndex];
    hero.moveXY(point.x, point.y);
    var enemy = hero.findNearestEnemy();
    var coin = hero.findNearestItem();
 
    if (enemy.team == "ogres" && enemy.health<10 ) {
        hero.attack(enemy);
    }
    // Collect a coin if coin.value is less than 5
    // AND its distance is less than 7
    if (coin.value < 5 && hero.distanceTo(coin)< 7 ) {
        hero.moveXY(coin.pos.x,coin.pos.y);
        hero.moveXY(point.x, point.y);
    }
    // Attack only if the enemy.health is less than 10
    // AND the enemy's type is "skeleton".
    if (enemy.type == "skeleton" && enemy.health<10) {
        hero.attack(enemy);
    }
    pointIndex ++;
}

for some reason the hero takes the wrong coin and wake up the enemies

Welcome to CodeComabat Discourse Forums @yani77 !
Here you can get assistance in levels, suggest things for the game, report any problems or bugs or just chat to other CoCo players! Remember to check the rules and guidelines if you haven’t already and have fun! :grinning_face_with_smiling_eyes:

1 Like

link to level pls 20 charas

CodeCombat - Coding games to learn Python and JavaScript?

1 Like

what the problem can u explain it to me error or else?

i will help if u tell me what the problem

i see maybe u need to delete this part hero.moveXY(point.x, point.y);try idk maybe it work and hero.moveXY(point.x, point.y); to hero.moveXY(point.[‘x’], point.[‘y’]);

nop it doesn’t work.
the problem is that i takes the wrong coin

Maybe instead of coin value just do it gold coin

try using

if #whatever:
    #collect or move

do

enemy=hero.findNearestEnemy()
if coin and enemy and hero.distanceTo(coin)<7 or enemy.distanceTo(coin)<#input:
    #collect