[SOLVED] Help with Wishing Well

hello everyone,

i’m having problems with wishing well. my hero will collect all the coins, which isn’t 104, and then an error will pop up that says "cannot read property pos of undefined.

// 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();
    // Get the total value of coins.
    var goldAmount = sumCoinValues(items);
    // If there are coins, then goldAmount isn't zero.
    if (goldAmount !== 0) {
        // If goldAmount is less than requiredGold
        // Then say "Non satis".
        if (goldAmount < requiredGold){
            hero.say(less);
        }
        // If goldAmount is greater than requiredGold
        if (goldAmount > requiredGold){
        // Then say "Nimis".
        hero.say(more);
        }
        // If goldAmount is exactly equal to requiredGold
        if (goldAmount == requiredGold){
        // If there is exactly 104 gold, then collect all coins.
    
        }
    }
     hero.moveXY(items[0].pos.x,items[0].pos.y);

    }

Thanks!

The error is coming from here:

for some reason it doesn’t work but you don’t need it anyway so I won’t try and work it out if you don’t mind. Instead use the collectAllCoins() function when the (gold Amount == required Gold).
Another thing: you’ve muddled up more and less and “Nimis” and “Non Satis” which is very easy since it’s a different language so you can’t even tell, you just need to switch the less with the more and the more with the less.
Apart from that your code is right. :grin:

that did it! you, sir, a true gentleman and a scholar

But thank you my kind sir for such a polite and gracious comment.

uh, okay…?(20 char)

What r u trying to say? Eh?

wait, question mark?

I’m just speaking nonsense, it doesn’t make sense.

sorry to bring up a dead thread but My hero just collects all the coins instead of 104.

Hi, please could you not ask for help in two locations, it won’t get you help any quicker and it clutters the forum and confuses me.
Thanks,
Danny

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