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!
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?
Can I see your recent code?
Andrei
Please could you also show us a screenshot of this issue.
Danny
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
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
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.
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.
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?