Shine Getter HELP!


#1

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)

#2

You need to define coin.


#3

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.


#4

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.


#5

Oops, yea you are right, my bad


#7

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)


#8

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)


#9

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)


#10
        coinIndex = 0

should be put in the while true loop, too.


#11

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)


#12

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


#13

self? Where did that old code come from?


#14

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


#15

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


#16

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)