Help with Wishing Well - Sarven Desert

Hi guys. I need help with Wishing Well. I already am correct at making sure Tharin collects the coins when it is 104 coins, but when I collect one coin then the hero says Non satis again and it made me run out of time and Tharin froze. Here’s my code:
// You need exactly 104 gold.

var less = “Nimis”;
var more = “Non satis”;
var requiredGold = 104;

// This function calculates the sum of all coin values.
function sumCoinValues(coins) {
var coinIndex = 0;
var totalValue = 0;
// Iterate all coins.
while (coinIndex < coins.length) {
totalValue += coins[coinIndex].value;
coinIndex++;
}
return totalValue;
}

function collectAllCoins() {
var item = hero.findNearest(hero.findItems());
while (item) {
hero.moveXY(item.pos.x, item.pos.y);
item = hero.findNearest(hero.findItems());
}
}

while (true) {
var items = hero.findItems();
var flag = hero.findFlag(“green”);
// Get the total value of coins.
var goldAmount = sumCoinValues(items);
// If there are coins, then goldAmount isn’t zero.
if (items.length !== 0) {
// If goldAmount is less than requiredGold
// Then say “Non satis”.
if (goldAmount<104) {
hero.say(“Non satis”);

    }
    // If goldAmount is greater than requiredGold
    // Then say "Nimis".
    if (goldAmount>104) {
        hero.say("Nimis");
    }
    // If goldAmount is exactly equal to requiredGold
    // If there is exactly 104 gold, then collect all coins.
    if (goldAmount == requiredGold) {
        hero.moveXY(items[0].pos.x, items[0].pos.y);
        }
    }
}

Thats all. Thank you for your kind attention. :slight_smile:

This happens because once a single coin is collected, the condition is no longer true, therefore the code iterates through again looking for 104 coins and you cannot continue to pick up coins.

You have the code for collect coins in the same loop as looking for the coins. Instead, try breaking out of that loop once 104 is reached. Then write another loop to moveXY and collect coins.

You have a separate function to collectAllCoins() but you never call the function in your code. Try something like this

if goldAmount == requiredGold:
    call the collectAllCoins function

Dude thank you so much man! Such a silly mistake but hard to find. I finally need to complete one more round for Sarven Desert. Thank you do I really appreciate your reply :slight_smile: