[SOLVED] Shine Getter HELP!

I’ve tried everything and nothing works plz help anything would be nice :slight_smile:

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

You need to define coin.

Umm… he does in here coin = coins[coinIndex] his problem is he is defining pos wrong, The pos class/function is already predefined by the codecombat source code. Delete pos=coin.pos and it should work.

No, he is defining coins in a while loop; inside the while loop is the

coins = self.findItems()
    coinIndex = 0

not on the outside. he needs to create a while True loop with the variables and while len(coins) < 3: inside.

Oops, yea you are right, my bad

It still dose’nt work, here is my code again

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

I realized one mistake, I forgot to put coins = self.findItems() above while len(coins) < 3: here is my code nowwhile True: coins = self.findItems() while len(coins) < 3: coinIndex = 0 # Wrap this into a loop that iterates over all coins. coin = coins[coinIndex] # Gold coins are worth 3. if coin.value == 3: # Only pick up gold coins. pos=coin.pos x = coin.pos.x y = coin.pos.y self.moveXY(x, y)

sry

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

        coinIndex = 0

should be put in the while true loop, too.

It still doesn’t work here is my code now

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

coinindex should be put in the while true loop as well.

self? Where did that old code come from?

I changed self into hero and it still dosen’t work!

Both methods work. Just that self is an alternative of hero.

This is your code with some additional comments:

while True:
    coins = self.findItems() # use hero instead of self, don't be sure they are the same thing
    coinIndex = 0
    hero.say('len(coins) = ' +  len(coins)) # picture added below
    # while len(coins) < 3:   # this will never be true
    while # add code  here to compare coinIndex with len(coins)
        # Wrap this into a loop that iterates over all coins.
        coin = coins[coinIndex]
        # Gold coins are worth 3.
        if coin.value == 3:
            # Only pick up gold coins.
            # pos=coin.pos # comment this line pos isn't same as pos in x = coin.pos.x or coin.pos.y
                                      # it's a new variable you don't use
            x = coin.pos.x
            y = coin.pos.y
            self.moveXY(x, y)
        # increment somewhere in the second while loop coinIndex to iterate through all the coins

I added hero.say('len(coins) = ’ + len(coins)) for debug and this is the picture:


So you must add a condition after while to compare coinIndex with len(coins)

while True:
    coins = hero.findItems()
    coinIndex = 0
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        if coin.value == 3:
            hero.moveXY(coin.pos.x, coin.pos.y)
            coinIndex += 1
            pass

I was maybe I could get some help from here

What happenes when coin.value is not 3?

Andrei

1 Like

oh thanks for asking but I actually finished it but thanks for asking

2 Likes

Then congratulations for completing the level!

Andrei