# \[SOLVED\] Help on Sand Snakes

**URL:** <https://discourse.codecombat.com/t/solved-help-on-sand-snakes/23186>\
**Category:** Level Help\
**Created:** [July 22, 2020, 4:36pm UTC](https://discourse.codecombat.com/t/solved-help-on-sand-snakes/23186 "2020-07-22T16:36:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![LunaFromTheMoon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lunafromthemoon/32/37747_2.png) [@LunaFromTheMoon](https://discourse.codecombat.com/u/LunaFromTheMoon)\
**Post date:** [July 22, 2020, 4:36pm UTC](https://discourse.codecombat.com/t/solved-help-on-sand-snakes/23186/1 "2020-07-22T16:36:50Z")

</div>

```python
# 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 😓

---

<div class="post-metadata">

**Author:** ![MidnightWolf39](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/midnightwolf39/32/13309_2.png) [@MidnightWolf39](https://discourse.codecombat.com/u/MidnightWolf39)\
**Post date:** [July 22, 2020, 5:00pm UTC](https://discourse.codecombat.com/t/solved-help-on-sand-snakes/23186/2 "2020-07-22T17:00:58Z")

</div>

Try putting your if nearest inside your while True loop

---

<div class="post-metadata">

**Author:** ![MidnightWolf39](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/midnightwolf39/32/13309_2.png) [@MidnightWolf39](https://discourse.codecombat.com/u/MidnightWolf39)\
**Post date:** [July 22, 2020, 5:04pm UTC](https://discourse.codecombat.com/t/solved-help-on-sand-snakes/23186/3 "2020-07-22T17:04:20Z")

</div>

Instead of coin.distance put distance and it should work

---

<div class="post-metadata">

**Author:** ![LunaFromTheMoon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lunafromthemoon/32/37747_2.png) [@LunaFromTheMoon](https://discourse.codecombat.com/u/LunaFromTheMoon)\
**Post date:** [July 22, 2020, 5:13pm UTC](https://discourse.codecombat.com/t/solved-help-on-sand-snakes/23186/4 "2020-07-22T17:13:42Z")

</div>

Thanks! (20 Characters)

---

<div class="post-metadata">

**Author:** ![MidnightWolf39](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/midnightwolf39/32/13309_2.png) [@MidnightWolf39](https://discourse.codecombat.com/u/MidnightWolf39)\
**Post date:** [July 22, 2020, 5:15pm UTC](https://discourse.codecombat.com/t/solved-help-on-sand-snakes/23186/5 "2020-07-22T17:15:17Z")

</div>

You’re welcome! 😁

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/a/a9445509d1a758c41b5ddcddc8c8e20a5dedb67f.png) [@system](https://discourse.codecombat.com/u/system)\
**Post date:** [July 23, 2020, 5:15am UTC](https://discourse.codecombat.com/t/solved-help-on-sand-snakes/23186/6 "2020-07-23T05:15:18Z")

</div>

Closed on July 23, 2020, 5:15am UTC

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