// 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];
coinIndex = coinIndex + 1
// Gold coins are worth 3.
if (coin.value == 3) {
// Only pick up gold coins.
hero.moveXY(goldcoin.pos.x, goldcoin.pos.y);
}
}
}
// 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];
// Gold coins are worth 3.
if (coin.value == 3) {
// Only pick up gold coins.
hero.moveXY(coin.pos.x, coin.pos.y);
}
}
}
In the original code you misses semicolon to coinIndex = coinIndex + 1 In the correction you totally deleted that row. You need it, but at the end of the loop. You cannot exit a loop without some exit action and in your case
this is the incrementation.
At the end of the while (coinIndex < coins.length loop, not in the end of if coin.value condition.
Ok, you have done it yourself!
Delete your code in the last message, we don’t have to post whole solutions. ( You can keep the thanks )