# \[SOLVED\] Sand Snakes problem

**URL:** <https://discourse.codecombat.com/t/solved-sand-snakes-problem/24638>\
**Category:** Level Help\
**Created:** [October 6, 2020, 2:04am UTC](https://discourse.codecombat.com/t/solved-sand-snakes-problem/24638 "2020-10-06T02:04:28Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Tang](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/eric_tang/32/15310_2.png) [@Eric\_Tang](https://discourse.codecombat.com/u/Eric_Tang)\
**Post date:** [October 6, 2020, 2:04am UTC](https://discourse.codecombat.com/t/solved-sand-snakes-problem/24638/1 "2020-10-06T02:04:28Z")

</div>

the code is not working for some reason I’m not sure if this is normal but every time I try, the coins move onto the trap and it kills my hero. My code is below.

```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.

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 (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.
    hero.moveXY(nearest.pos.x,nearest.pos.y)

```

---

<div class="post-metadata">

**Author:** ![Chaboi\_3000](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chaboi_3000/32/48486_2.png) [@Chaboi\_3000](https://discourse.codecombat.com/u/Chaboi_3000)\
**Post date:** [October 6, 2020, 2:54am UTC](https://discourse.codecombat.com/t/solved-sand-snakes-problem/24638/2 "2020-10-06T02:54:05Z")

</div>

@Eric_Tang, welcome to the forums!

I just tried running your code, and it ran successfully. This might be an equipment issue. Care to screenshot your equipment and send it here?

---

<div class="post-metadata">

**Author:** ![MrVictor19](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/mrvictor19/32/17059_2.png) [@MrVictor19](https://discourse.codecombat.com/u/MrVictor19)\
**Post date:** [October 6, 2020, 4:02am UTC](https://discourse.codecombat.com/t/solved-sand-snakes-problem/24638/3 "2020-10-06T04:02:53Z")

</div>

@Chaboi_3000 is correct, you probably need better armour.

---

<div class="post-metadata">

**Author:** ![Lydia\_Song](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lydia_song/32/31461_2.png) [@Lydia\_Song](https://discourse.codecombat.com/u/Lydia_Song)\
**Post date:** [October 6, 2020, 4:24am UTC](https://discourse.codecombat.com/t/solved-sand-snakes-problem/24638/4 "2020-10-06T04:24:54Z")

</div>

Welcome‌ ‌welcome‌ @Eric_Tang ‌to‌ ‌the‌ ‌forum!‌ ‌It‌ ‌is‌ ‌a‌ ‌lovely‌ ‌place‌ ‌where‌ ‌you‌ ‌can‌ ‌share‌ ‌all‌ ‌kinds‌ ‌of‌ stuff‌ ‌(appropriate‌ ‌of‌ ‌course),‌ ‌share‌ ‌bugs,‌ ‌and‌ ‌even‌ ‌get‌ ‌assistance‌ ‌for‌ ‌code!‌ ‌We‌ ‌suggest‌ ‌that‌ ‌you‌ ‌review‌ ‌[this‌‌ topic](https://discourse.codecombat.com/t/welcome-to-codecombat-discourse-forums/15601%E2%80%8C)‌ ‌which‌ ‌shows‌ ‌all‌ ‌essentials‌ ‌of‌ ‌this‌ ‌board!‌ ‌And‌ ‌we‌ ‌suggest‌ ‌you‌ ‌review‌ [this topic](https://discourse.codecombat.com/t/essentials-how-to-post-format-your-code-correctly/15521)‌ ‌which‌ ‌shows‌ ‌how‌ ‌to‌ ‌post‌ ‌your‌ ‌code‌ ‌correctly!‌ ‌Thanks!!‌ ‌ 🥳 🥳

> [@Eric\_Tang](#):
>
> ```python
> # If there's a nearest coin, move to its position. You'll need moveXY so you don't cut corners and hit a trap.
> hero.moveXY(nearest.pos.x,nearest.pos.y)
> 
> ```

Check if there is a nearest coin.

> [@Eric\_Tang](#):
>
> `if (distance<nearestDistance):`

Do you need parentheses? You can get rid of them.  
Lydia

---

<div class="post-metadata">

**Author:** ![Chaboi\_3000](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chaboi_3000/32/48486_2.png) [@Chaboi\_3000](https://discourse.codecombat.com/u/Chaboi_3000)\
**Post date:** [October 6, 2020, 4:25am UTC](https://discourse.codecombat.com/t/solved-sand-snakes-problem/24638/5 "2020-10-06T04:25:52Z")

</div>

> [@Lydia\_Song](#):
>
> Check if there is a nearest coin.

As I stated above, his code works correctly, so the equipment must be funky.

---

<div class="post-metadata">

**Author:** ![Lydia\_Song](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lydia_song/32/31461_2.png) [@Lydia\_Song](https://discourse.codecombat.com/u/Lydia_Song)\
**Post date:** [October 6, 2020, 4:30am UTC](https://discourse.codecombat.com/t/solved-sand-snakes-problem/24638/6 "2020-10-06T04:30:24Z")

</div>

@Chaboi_3000 I know, but maybe that is the problem?  
@Eric_Tang, do you have glasses equipped that will allow you to check findEnemies()?  
And do you have boots that will allow you to use moveXY() ?  
They don’t cost much if you go for the lowest amount of gems.  
Also make sure that your language is in Python.  
Lydia

---

<div class="post-metadata">

**Author:** ![Chaboi\_3000](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chaboi_3000/32/48486_2.png) [@Chaboi\_3000](https://discourse.codecombat.com/u/Chaboi_3000)\
**Post date:** [October 6, 2020, 4:31am UTC](https://discourse.codecombat.com/t/solved-sand-snakes-problem/24638/7 "2020-10-06T04:31:15Z")

</div>

> [@Lydia\_Song](#):
>
> I know, but maybe that is the problem?

There’s always a coin present(Even the bad coins), so that shouldn’t be an issue.

---

<div class="post-metadata">

**Author:** ![MrVictor19](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/mrvictor19/32/17059_2.png) [@MrVictor19](https://discourse.codecombat.com/u/MrVictor19)\
**Post date:** [October 6, 2020, 4:36am UTC](https://discourse.codecombat.com/t/solved-sand-snakes-problem/24638/8 "2020-10-06T04:36:24Z")

</div>

I can’t really see anything wrong with @Eric_Tang’s code.

---

<div class="post-metadata">

**Author:** ![Eric\_Tang](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/eric_tang/32/15310_2.png) [@Eric\_Tang](https://discourse.codecombat.com/u/Eric_Tang)\
**Post date:** [October 6, 2020, 2:10pm UTC](https://discourse.codecombat.com/t/solved-sand-snakes-problem/24638/9 "2020-10-06T14:10:02Z")

</div>

I have all of those things but they don’t work. I tried to take off anything that was unnecessary, but it still doesn’t work. I also tried to switch my hero.

---

<div class="post-metadata">

**Author:** ![Eric\_Tang](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/eric_tang/32/15310_2.png) [@Eric\_Tang](https://discourse.codecombat.com/u/Eric_Tang)\
**Post date:** [October 6, 2020, 2:11pm UTC](https://discourse.codecombat.com/t/solved-sand-snakes-problem/24638/10 "2020-10-06T14:11:10Z")

</div>

My coins also seem to move to my hero and that is the problem. Is that normal?

---

<div class="post-metadata">

**Author:** ![Eric\_Tang](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/eric_tang/32/15310_2.png) [@Eric\_Tang](https://discourse.codecombat.com/u/Eric_Tang)\
**Post date:** [October 6, 2020, 2:20pm UTC](https://discourse.codecombat.com/t/solved-sand-snakes-problem/24638/11 "2020-10-06T14:20:52Z")

</div>

Does it have anything to do with the characters?

---

<div class="post-metadata">

**Author:** ![Code\_Master](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/code_master/32/16184_2.png) [@Code\_Master](https://discourse.codecombat.com/u/Code_Master)\
**Post date:** [October 6, 2020, 4:11pm UTC](https://discourse.codecombat.com/t/solved-sand-snakes-problem/24638/12 "2020-10-06T16:11:57Z")

</div>

Are you using the mimic? It attracts coins. Take it off! And I think that is the only problem from what you are describing.

---

<div class="post-metadata">

**Author:** ![Lydia\_Song](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lydia_song/32/31461_2.png) [@Lydia\_Song](https://discourse.codecombat.com/u/Lydia_Song)\
**Post date:** [October 6, 2020, 7:28pm UTC](https://discourse.codecombat.com/t/solved-sand-snakes-problem/24638/13 "2020-10-06T19:28:31Z")

</div>

Try un-equipping all of your armor and pets.  
Lydia

---

<div class="post-metadata">

**Author:** ![Eric\_Tang](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/eric_tang/32/15310_2.png) [@Eric\_Tang](https://discourse.codecombat.com/u/Eric_Tang)\
**Post date:** [October 6, 2020, 9:25pm UTC](https://discourse.codecombat.com/t/solved-sand-snakes-problem/24638/14 "2020-10-06T21:25:14Z")

</div>

I’m at school, I’ll try when I get home.

---

<div class="post-metadata">

**Author:** ![Eric\_Tang](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/eric_tang/32/15310_2.png) [@Eric\_Tang](https://discourse.codecombat.com/u/Eric_Tang)\
**Post date:** [October 6, 2020, 9:32pm UTC](https://discourse.codecombat.com/t/solved-sand-snakes-problem/24638/15 "2020-10-06T21:32:03Z")

</div>

it works!!! thanks! Code\_Master

---

<div class="post-metadata">

**Author:** ![Code\_Master](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/code_master/32/16184_2.png) [@Code\_Master](https://discourse.codecombat.com/u/Code_Master)\
**Post date:** [October 6, 2020, 10:46pm UTC](https://discourse.codecombat.com/t/solved-sand-snakes-problem/24638/16 "2020-10-06T22:46:17Z")

</div>

Glad it helped!(20 chars)

---

<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:** [October 7, 2020, 10:46am UTC](https://discourse.codecombat.com/t/solved-sand-snakes-problem/24638/17 "2020-10-07T10:46:21Z")

</div>

Closed on October 7, 2020, 10:46am UTC

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