Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] Need help wishing well

super sorry for the continous posting i’ll try not to any more

    if goldAmount != 0:
        # If goldAmount is less than requiredGold
        if goldAmount < requiredGold:
            # Then say "Non satis".
            hero.say("Non statis")
        # If goldAmount is greater than requiredGold
        if goldAmount>requiredGold:
            # Then say "Nimis".
            hero.say("Nimis")
        # If goldAmount is exactly equal to requiredGold
        if goldAmount==requiredGold:
            # Then collect all coins:
            hero.say("all done")
        pass

Post away as much as you want. As long as it’s Code Combat related, that’s what this board is for. :smiley:

okay thanks:grinning::grinning:

Well, for starters, your code needs to be in a while True loop. Also, you’ve not defined goldAmount or requiredGold anywhere.

actualy i did just i forgot to show that part of my code

Please post all of your code. No one can possibly assist you unless we can see your entire code.

okay

# You need exactly 104 gold. 

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

# This function calculates the sum of all coin values.
def sumCoinValues(coins):
    coinIndex = 0
    totalValue = 0
    # Iterate all coins.
    while coinIndex < len(coins):
        totalValue += coins[coinIndex].value
        coinIndex += 1
    return totalValue

def collectAllCoins():
    item = hero.findNearest(hero.findItems())
    while item:
        hero.moveXY(item.pos.x, item.pos.y)
        item = hero.findNearest(item)

while True:
    items = hero.findItems()
    # Get the total value of coins.
    goldAmount = sumCoinValues(items)
    # If there are coins, then goldAmount isn't zero.
    if goldAmount != 0:
        # If goldAmount is less than requiredGold
        if goldAmount < requiredGold:
            # Then say "Non satis".
            hero.say("Non statis")
        # If goldAmount is greater than requiredGold
        if goldAmount>requiredGold:
            # Then say "Nimis".
            hero.say("Nimis")
        # If goldAmount is exactly equal to requiredGold
        if goldAmount==requiredGold:
            # Then collect all coins:
            hero.say("all done")
        pass

sorry MunkeyShynes i won’t forget next time

Look at the comments above.

Hint: You never call the function to collectAllCoins() in the while True loop

okay I’ll try that :grinning:

for some reason, it still did not work???

Just wait a minute and try again with another seed. If it works when you click run, it should work when you submit.

Update: You have a typo.

did not work when there’s 104 gold my hero won’t move ???

Did you correct the typo?

where is the typo???

and also is this how you told me to arange collectAllCoins??
while true loop is at the top on this position

while true:
if goldAmount==requiredGold:
    # Then collect all coins:
    collectAllCoins()
    pass

With what little I can see from your post, it looks like you have called the function properly. I’m not going to tell you where the typo is for a good reason. Many times you will find yourself combing through a bazillion lines of code just to find an error. You need to learn to do this. A friend of mine once spent 6 hours going through a huge section of code he wrote to debug it. He finally found the problem and it was a comma where a period should have been. Line by line, word by word. It’s part of programming. You’ll find it. Just go slow and look at every word individually.

okay I’ll try and find the typo thanks :slightly_smiling_face::slightly_smiling_face::slightly_smiling_face:

found it thanks MunkeyShynes :smile: