Shine getter javascript infinite loops[SOLVED]

this frustrating i keep getting infinite loops

// To grab the most gold quickly, just go after gold coins.

while(true) {
    var coins = hero.findItems();
    var coinIndex = 0;
    // Wrap this into a loop that iterates over all coins.
    while(coinIndex < coins.length) {
        var coin = coins[coinIndex];
        if (coin.value === 3) {
            hero.moveXY(coin.pos.x, coin.pos.y);
        }
    }
}

not sure about js, but i dont think there should be 3 equal marks

already remove that still doesn’t work.

1 Like

you aren’t incrementing coinIndex, so it is giving you infinite loop

ok i try that (20 character)

// To grab the most gold quickly, just go after gold coins.

while(true) {
    var coins = hero.findItems();
    var coinIndex = 0;
    // Wrap this into a loop that iterates over all coins.
    while(coinIndex < coins.length) {
        var coin = coins[coinIndex];
        if (coin.value == 3) {
            hero.moveXY(coin.pos.x, coin.pos.y);
            coinIndex += 1;
        }
    }
}

stil not working
@Aya

That’s not how it is done in javascript, it would be coinIndex ++
and put it outside the if statement

ohok 20 chararacterrs

now i get error at this part.
@Aya

Code? (20 c h a r s )

// To grab the most gold quickly, just go after gold coins.

while(true) {
    var coins = hero.findItems();
    var coinIndex = 0;
    // Wrap this into a loop that iterates over all coins.
    while(coinIndex < coins.length) {
        var coin = coins[coinIndex];
        if (coin.value == 3) {
            hero.moveXY(coin.pos.x, coin.pos.y);
            coinIndex ++ 1;
        }
    }
}

Put this outside the if statement

same…

// To grab the most gold quickly, just go after gold coins.

while(true) {
    var coins = hero.findItems();
    var coinIndex = 0;
    // Wrap this into a loop that iterates over all coins.
    while(coinIndex < coins.length) {
        var coin = coins[coinIndex];
        if (coin.value == 3) {
            hero.moveXY(coin.pos.x, coin.pos.y);
        }
        coinIndex ++ 1;
    }
}

it is coinIndex ++; not coinIndex ++ 1;

thanks @Aya finnaly working

1 Like

You’re welcome (20chars)

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.