How do I to prioritize gold coins, then silver and copper in their respective order?


#1

In the level “Sarven Treasure”, I try to find the Nearest gold coin first, then silver, then copper last: but every code I try doesn’t seem to work! Please help ASAP!


#2

All coins have a value, with gold being worth 3, silver worth 2, and bronze 1. To find them, you can use something like this:

coins = [c for c in self.findItems() if c.value == x]

Where x is the value that you are searching for.


#3

Oh, I’m a JavaScript user…


#4

Well, in that case, use this:

var coins = this.findItems();
var coinList = []; 
var coinIndex = 0;
var coinValue = "Whatever value you want";
while (coinIndex < coins.length) {
    var coin = coins[coinIndex];
    if (coin.value === coinValue) {
        coinList.push(coin);
    }
}

#5

Wow, thanks! I’ll try it out and see how it works. I’ll let you know of the results…