Need help wishing well[SOLVED]


#1

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


#2

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


#3

okay thanks:grinning::grinning:


#4

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


#5

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


#6

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


#7

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


#8

sorry MunkeyShynes i won’t forget next time


#9

Look at the comments above.

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


#10

okay I’ll try that :grinning:


#11

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


#14

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.


#15

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


#16

Did you correct the typo?


#17

where is the typo???


#18

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


#19

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.


#20

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


#21

found it thanks MunkeyShynes :smile: