Shine Getter / Sarven Shepard

Hi

I’ve completed both Sarven Shepard and Shine Getter,but I’m struggling to grasp a few of what I imagine are the key take aways / learning points.

My code for Shine Getter was:

loop:
    coins = self.findItems()
    coinIndex = 0
    
    # Wrap this into a loop that iterates over all coins.
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        coinIndex += 1
 # Gold coins are worth 3.
        if coin.value == 3:
    # Only pick up gold coins.
            pos = coin.pos
            x = pos.x
            y = pos.y
            self.moveXY(x, y)

What I’m finding hard to grasp is why the code doesn’t run when I use the following:

while coinIndex < 100:

or

coinIndex += coin.value

Whenever I try running the code with the above my char just sits there or I get an error. Yet as far as I can work out, they should both work?

What am I missing / not getting?

1 Like

For the first one, you assume there are at least one hundred coins. But if there are only fifty coins, you can’t try to collect a fifty-first coin, which is what you will try to do.

As for the second, you want to loop over each coin, one at a time. If you add the value of a coin, and it is not a bronze coin, you will be skipping coins.