# Sand Snakes - My Player is Lazy

**URL:** <https://discourse.codecombat.com/t/sand-snakes-my-player-is-lazy/37253>\
**Category:** Level Help\
**Created:** [March 26, 2024, 4:54pm UTC](https://discourse.codecombat.com/t/sand-snakes-my-player-is-lazy/37253 "2024-03-26T16:54:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![WeAreTheWarriors](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/wearethewarriors/32/37053_2.png) [@WeAreTheWarriors](https://discourse.codecombat.com/u/WeAreTheWarriors)\
**Post date:** [March 26, 2024, 4:54pm UTC](https://discourse.codecombat.com/t/sand-snakes-my-player-is-lazy/37253/1 "2024-03-26T16:54:45Z")

</div>

I need help here.

```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.
nearestCoin = 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 nearestCoin < nearestDistance:
            # Set nearest to coin
            nearest == nearestCoin
            # 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(coins.pos.x, coins.pos.y)

```

---

<div class="post-metadata">

**Author:** ![WeAreTheWarriors](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/wearethewarriors/32/37053_2.png) [@WeAreTheWarriors](https://discourse.codecombat.com/u/WeAreTheWarriors)\
**Post date:** [March 26, 2024, 4:55pm UTC](https://discourse.codecombat.com/t/sand-snakes-my-player-is-lazy/37253/2 "2024-03-26T16:55:04Z")

</div>

Any ideas on how to get me guy to ACTUALLY MOVE?

---

<div class="post-metadata">

**Author:** ![MarmiteOnToast](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/marmiteontoast/32/46649_2.png) [@MarmiteOnToast](https://discourse.codecombat.com/u/MarmiteOnToast)\
**Post date:** [March 26, 2024, 5:41pm UTC](https://discourse.codecombat.com/t/sand-snakes-my-player-is-lazy/37253/3 "2024-03-26T17:41:17Z")

</div>

I’ll be able to check your code in a few minutes, but I’ve noticed that you’ve placed `hero.moveXY` underneath the while True loop, so it’ll never run.

---

<div class="post-metadata">

**Author:** ![Buddeycc](https://avatars.discourse-cdn.com/v4/letter/b/54ee81/32.png) [@Buddeycc](https://discourse.codecombat.com/u/Buddeycc)\
**Post date:** [March 26, 2024, 10:26pm UTC](https://discourse.codecombat.com/t/sand-snakes-my-player-is-lazy/37253/4 "2024-03-26T22:26:34Z")

</div>

Put the hero.moveXY in the while True loop

---

<div class="post-metadata">

**Author:** ![WeAreTheWarriors](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/wearethewarriors/32/37053_2.png) [@WeAreTheWarriors](https://discourse.codecombat.com/u/WeAreTheWarriors)\
**Post date:** [March 26, 2024, 10:27pm UTC](https://discourse.codecombat.com/t/sand-snakes-my-player-is-lazy/37253/5 "2024-03-26T22:27:31Z")

</div>

Did that, the computer doesn’t recognize ‘x’

---

<div class="post-metadata">

**Author:** ![Buddeycc](https://avatars.discourse-cdn.com/v4/letter/b/54ee81/32.png) [@Buddeycc](https://discourse.codecombat.com/u/Buddeycc)\
**Post date:** [March 26, 2024, 10:35pm UTC](https://discourse.codecombat.com/t/sand-snakes-my-player-is-lazy/37253/6 "2024-03-26T22:35:04Z")

</div>

you should look at the nearest coin not the list “coins” because you need a singular object to check it’s position

---

<div class="post-metadata">

**Author:** ![WeAreTheWarriors](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/wearethewarriors/32/37053_2.png) [@WeAreTheWarriors](https://discourse.codecombat.com/u/WeAreTheWarriors)\
**Post date:** [March 27, 2024, 3:48pm UTC](https://discourse.codecombat.com/t/sand-snakes-my-player-is-lazy/37253/7 "2024-03-27T15:48:26Z")

</div>

I don’t understand. Please elaborate

---

<div class="post-metadata">

**Author:** ![WeAreTheWarriors](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/wearethewarriors/32/37053_2.png) [@WeAreTheWarriors](https://discourse.codecombat.com/u/WeAreTheWarriors)\
**Post date:** [March 27, 2024, 3:53pm UTC](https://discourse.codecombat.com/t/sand-snakes-my-player-is-lazy/37253/8 "2024-03-27T15:53:09Z")

</div>

I asked the AI. It’s all good now, thanks for helping!

---

<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:** [March 28, 2024, 3:54am UTC](https://discourse.codecombat.com/t/sand-snakes-my-player-is-lazy/37253/9 "2024-03-28T03:54:05Z")

</div>

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