Wishing Well - "Ran out of time" Bug (Python)


#1

Hi all - First time through Code Combat and I’m stuck at the “Wishing Well” level on the desert map. I’m pretty confident my code is good, and I’ve even tried code from other users for this level, but the level keeps saying “Goals: Ran out of time”. One thing I noticed is that the amount of gold shown at the top of the screen keeps increasing until it gets to ~190 gold, then never goes down again. Is this a bug, or am I doing something wrong? Please help because I can’t progress in this game…

less = "Nimis"
more = "Non satis"
requiredGold = 104

# This function calculates the sum of coin values. 
def sumCoinValues(coins):
    total = 0
    for coin in coins:
        total += coin.value
    return total

def collectCoins(coins):
    for coin in coins:
        hero.moveXY(coin.pos.x, coin.pos.y)

while True:
    items = hero.findItems()
    goldAmount = sumCoinValues(items)
    if len(items) != 0:
        # If there is not enough gold, then say "Non satis".
        if goldAmount < requiredGold:
            hero.say(less)
        elif goldAmount > requiredGold:
            hero.say(more)
        elif goldAmount == requiredGold:
            collectCoins(items)

#2

etc.

If there isn’t enough gold, hero.say(more). If there is too much, hero.say(less). It was just a simple variable mix-up. If you look at the top of your code, you can see that the string “Non satis” is defined as more (there is not enough gold, so you need more), and that the string “Nimis” is defined as less (there is too much gold, so you need less).
Hope this helps! :slight_smile:


#3

Did you mess up on !=?


#4

I don’t think that’s an error because that line makes the next code block iterate if there are coins (i.e. there are not 0 coins since != means not, and I don’t think it’s possible to have less than 0 coins on this level). :slight_smile: