[Solved] Sand snakes (Python)

This is what happens :smiley:

1 Like

@chaboi_3000 i have no clue what’s going on aaaa

1 Like

Ok, while we’re waiting for him, would you help me with the horse level?

Wild horses? (20 chars)

There’s no such thing as coin.distance, only hero.distanceTo(coin)

It gives the same error though:

My code:

# 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.
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 hero.distanceTo(coin) < nearestDistance:
            nearest = coin
            nearestDistance = coin.distance
            
            hero.moveXY(nearest.pos.x, nearest.pos.y)

            # Set nearest to coin
            
            # Set nearestDistance to 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.


Did you read any of this?

You are assigning nearestDistance to coin.distance still.

Try hero.distanceTo(coin)

That’s what I’m doing.
image

No? Look at the screenshot more carefully and tell me if you cannot see coin.distance.

Ohhhhh. I think I corrected it. But now I get blown up again.

        if hero.distanceTo(coin) < nearestDistance:
            nearest = coin
            nearestDistance = hero.distanceTo(coin)
            
            hero.moveXY(nearest.pos.x, nearest.pos.y)

        if hero.distanceTo(coin) < nearestDistance:
            nearest = coin
            nearestDistance = hero.distanceTo(coin)
            
    hero.moveXY(nearest.pos.x, nearest.pos.y)

Thank you so much guys! I finally passed!

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