A Fine Mint (python) ran out of time


#1

I’ve looked at this question and I have a firm grasp of python. It looks like my hero is killing peons and continuously picking up coins but time runs out apparently with the ‘RAN OUT OF TIME’ message. Am I missing something?

def pickUpCoin():
    coin = hero.findNearestItem()
    if coin:
        hero.moveXY(coin.pos.x, coin.pos.y)

# Write the attackEnemy function below.
# Find the nearest enemy and attack them if they exist!
def attackEnemy():
    nearest = hero.findNearestEnemy()
    if nearest:
        hero.attack(nearest)

while True:
    attackEnemy() # ∆ Uncomment this line after you write an attackEnemy function.
    pickUpCoin()

A Fine Mint - Ran out of time
#2

Your code looks fine, I’ll need to do some digging.

Please send email us at team@codecombat.com so I can inspect your session.


#3

Ok I changed

hero.moveXY(coin.pos.x, coin.pos.y)

to

hero.move({'x':coin.pos.x, 'y':coin.pos.y})

and it worked


#4

MoveXY => move can be a solution, but those boots are not expected in the forest. So there can be a problem anyway. Could you send email as Serg asked you? It can help us to find the problem and fix it.


#5

it worked for me, but thanks!


#6

It works…change the code to:

hero.move({‘x’:coin.pos.x, ‘y’:coin.pos.y})

Thanks a lot…finally solve it…


#7

Please Do not respond to dead topics


#8

Can you help me, please.
I have the same problem. (Ran out of time)
Thank you

def pickUpCoin():
    coin = hero.findNearestItem()
    if coin:
        hero.moveXY(coin.pos.x, coin.pos.y)
def attackEnemy():
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
while True:
    attackEnemy() 
    pickUpCoin()

#9

Please learn to post your code properly.

To post your code from the game, use the </> button or it won’t format properly. When you click the </> button, the following will appear:

Please paste ALL of your code inside the triple back tick marks.

``` <— Triple back tick marks.

Paste ALL of your code in here.

``` <— Triple back tick marks.

There are many people here willing and able to help. If you use the </> button correctly, then ALL of your code should look like this:

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
    else:
        hero.say("My code is formatted properly")

If ALL of your code isn’t formatted like the code above, then you’re doing it wrong and we can’t see the structure of the code to troubleshoot whether or not that is the issue. Use the </> button and help us help you. This works when sending a private message as well.

Thank you.


#10

Thank you. I changed Hero - it was a problem.
with code everything ok.