[SOLVED] Sand Snakes problem

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.


# 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)
1 Like

@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?

@Chaboi_3000 is correct, you probably need better armour.

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‌ ‌which‌ ‌shows‌ ‌all‌ ‌essentials‌ ‌of‌ ‌this‌ ‌board!‌ ‌And‌ ‌we‌ ‌suggest‌ ‌you‌ ‌review‌ this topic‌ ‌which‌ ‌shows‌ ‌how‌ ‌to‌ ‌post‌ ‌your‌ ‌code‌ ‌correctly!‌ ‌Thanks!!‌ ‌ :partying_face: :partying_face:

Check if there is a nearest coin.

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

1 Like

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

@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

1 Like

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

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

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.

1 Like

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

1 Like

Does it have anything to do with the characters?

1 Like

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

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

1 Like

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

it works!!! thanks! Code_Master

1 Like

Glad it helped!(20 chars)

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