Shine Getter(Python) Help!

When I try to do this level my avatar doesn’t move
This is my code:


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

There’s a few issues here with your code. First, you’ve not defined coins. Also, inside the while coinIndex < len(coins): loop, you’ve not defined coin properly. Third, you tell the hero to moveXY to coin position coordinates, but then follow with an if conditional statement and tell the hero to moveXY if the coin.value == 3. There should only be one move statement in this code (the second one is correct). Lastly, the coinIndex should be incremented at the end.

My character still doesn’t move.
My code:

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

1 Like

I think you need to indent the whole while loop into the while true loop.

1 Like