[SOLVED] Help on Sand Snakes

# This field is covered in firetraps.  Thankfully we've sent a scout ahead to find a path.  He left coins along the path so that if we always stick to the nearest coin, we'll avoid the traps.

# This canyon seems to interfere with your findNearest glasses!
# You'll need to find the nearest coins on your own.
coins = hero.findItems()
while True:
    coins = hero.findItems()
    coinIndex = 0
    nearest = None
    nearestDistance = 9999
    
    # Loop through all the coins to find the nearest one.
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        coinIndex += 1
        distance = hero.distanceTo(coin)
        # If this coin's distance is less than the nearestDistance
        if coin.distance < nearestDistance:
            
            # Set nearest to coin
            nearest = coin
            # Set nearestDistance to distance
            nearestDistance = distance
            
    # If there's a nearest coin, move to its position. You'll need moveXY so you don't cut corners and hit a trap.
if nearest:
        
    hero.moveXY(nearest.pos.x, nearest.pos.y)

My character just doesn’t move :sweat:

Try putting your if nearest inside your while True loop

1 Like

Instead of coin.distance put distance and it should work

1 Like

Thanks! (20 Characters)

1 Like

You’re welcome! :grin:

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.