Backwoods Standoff - running out of time

I could use some help with this. From what I can tell, my code is correct, but I keep running out of time.

First, welcome to the forum!

For your issue, I think the problem is in these lines of code:

if enemy:
    hero.isReady("cleave")
    hero.cleave(enemy)
else:
    hero.attack(enemy)

You should be checking for if the hero can cleave (lines 8-9). You should also attack the enemy only when it exists. Your code should look something like this

if an enemy exists:
    if the hero can cleave the enemy:
        then cleave the enemy
    else:
        then attack the enemy

hope this helps!

-@anna

Thank you for that advice, Anna. My hero can cleave. She kills the munchkins - three rounds of them. The result I get from the game is a message that I ā€œran out of time.ā€

Wait so it still doesnā€™t work?

Yes. The code runs. My hero cleaves. Three onslaughts of munchkins die. And I run out of time. I canā€™t figure out what is wrong.

Can you post your changed code?

Itā€™s up at the top of this thread.

I just looked over my code. I added a pass to the end after the else statement. Aside from what the advice I gave you at the top, I canā€™t find any other issues. @Deadpool198, @AnSeDra, @dedreous, @Chaboi_3000, any ideas?

1 Like

Can I see your recent code?

Andrei

Please could you also show us a screenshot of this issue.
Danny

2 Likes

Yes, your hero can cleave, since they have the correct sword. However, once he cleaveā€™s there is a ā€˜cooldownā€™ period, which means you must wait for this move to be available again. As written, your hero constantly tries to cleave. Instead, try this:

if enemy and hero.is ready to cleave, then:
    cleave
elif enemy:
    kill it
2 Likes

Thatā€™s funny. I did it with the else instead of the elif and it didnā€™t say ā€˜ran out of timeā€™.

hehā€¦well, if you completed the level, thatā€™s what counts!

I only used the ā€˜elifā€™ to test for enemy againā€¦not always required, but is a good habit to get in to.

Mod edit: thank you for posting, but solutions are not allowed.
This was my code and it worked for me. Hope this helps.
-Song

Hi @Lydia_Song, Thanks for trying to help, but sharing solutions is against the rules of this forum. Instead we try to help people understand code and coding so they can use it in the future.
ā€œGive a man a fish and heā€™ll eat for a day; teach a man to fish, and heā€™ll eat for a lifetimeā€ (or woman, either one).
Iā€™ve removed the code.
Thanks
Danny

2 Likes

Here is a screenshot of my code. Iā€™ve also tried following advice from @dedreous in line 10, but the results are the same. My hero survives, but I get a message that Iā€™ve run out of time.

Hereā€™s what my game looks like.

Kowensā€¦delete line 8, it does absolutely nothing. Edit line 7 to equate this statement:

if there is an enemy AND the hero is ready to cleave, then:

Ok, I wonā€™t post solutions again.

3 Likes

Thank you @dedreous. Iā€™m very new at this and I canā€™t figure out how to add the additional command in the code. I keep getting error messages, because Iā€™m doing wrong. Can you give me some guidance?