[SOLVED] Mad Maxer.... Why are there so many? (Sells Out (Help))

// Coins here disappear after a few seconds!
// Get all the gold coins before they vanish.

while(true) {
    var closestGold = null;
    var minGoldDist = Infinity;
    var coinIndex = 0;
    var coins = hero.findItems();
    // Find the closest coin that is gold.
    // Remember that gold coins have a value of 3.
    if (coins.value > 2) {
        hero.moveXY(coins.pos.x,coins.pos.y);
    }
    if(closestGold) {
        // Now go to the closest gold coin and get it!
        hero.moveXY(closestGold.pos.x,closestGold.pos.y);
    }
}

1 Like

Here try to loop over all the coins and find out the hero.distanceTo(coin) and if coin.value == 3 and distance < minGoldDist, then update the minGoldDist to distance and update the closestGold to coin.

Andrei

2 Likes

Please just help in one for now. I have to move through everything looking at what you just typed.

1 Like

Do you understand what I told you there or not?

2 Likes

Nope I do not understand

1 Like

Here put

while (coinIndex < coins.length){
    var coin = coins[coinIndex];
    var distance = hero.distanceTo(coin);
    if (coin.value == 3 && distance < minGoldDist){
        //here make closestCoin to be coin
        //here make minGoldDist to be distance
        pass;
    }
}

Andrei

2 Likes

wait a sec let me finish sarven siege

2 Likes

Try to focus at only one level at a time.

Andrei

2 Likes

Ok. So, no multitasking.

2 Likes

Yes. Because you should complete a level and after that try another one.

Andrei

2 Likes

Ithink my computer is gonna crash

1 Like

@Monsty can you show your new code please?

??

1 Like

my code:

return;  //Commented out to stop infinite loop.
// Coins here disappear after a few seconds!
// Get all the gold coins before they vanish.

while(true) {
    var closestGold = null;
    var minGoldDist = Infinity;
    var coinIndex = 0;
    var coins = hero.findItems();
    // Find the closest coin that is gold.
    // Remember that gold coins have a value of 3.
    while (coinIndex < coins.length){
    var coin = coins[coinIndex];
    var distance = hero.distanceTo(coin);
    if (coin.value == 3 && distance < minGoldDist){
        //here make closestCoin to be coin
        //here make minGoldDist to be distance
        pass;
    }
}
    if(closestGold) {
        // Now go to the closest gold coin and get it!
        hero.moveXY(closestGold.pos.x,closestGold.pos.y);
    }
}
1 Like

what’s this about???

1 Like

there was an infinite loop and you can’t go back into an infinite looped level

here you need to do what’s in the comments

1 Like

After this put coinIndex++; so you won’t have an infinity loop.

Andrei

2 Likes

I reset all my code but it won’t let me in

1 Like

What I told him to do in the comments.

Andrei

2 Likes