Sand Snakes plz help

Hello again! I haven’t been on for a long time and need some help with this level.

# 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.
items = 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
        
            # 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.
hero.moveXY(coin.pos.x,coin.pos.y)

easy, cheat with a flag and this code

while(true) {
    if (hero.findFlag("black")) {
        var flag = hero.findFlag("black");
        hero.pickUpFlag(flag);
    }
}

Hi @R.Loke, please don’t cheat or encourage cheating in CodeCombat on the Discourse.
This is a place for learning how to code. You’re not supposed to skip through the levels or cheat with flags.


Welcome back James! It looks like the last line of your code isn’t indented properly, and since it’s outside a while True loop, it’ll never run. You’ve also missed an if loop here:

I’m not gonna cheat but I am very rusty on coding and I’m not sure how to do this… :frowning_face:

never mind. I found out how to do this lv

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