Code bug on lvl "Woodland Cleaver"

Hello, i was wondering if this was a problem with my code, i have been doing some research on this and apparently this was supposed to have been fixed along time ago so i doubt its something to do with my code. Been stuck on this for about an hour. # Use your new “cleave” skill as often as you can.

self.moveXY(23, 23)
loop:
enemy = self.findNearestEnemy()
if self.isReady(“cleave”):
# Cleave the enemy!
self.cleave(enemy)
else:
# Else (if cleave isn’t ready), do your normal attack.
self.attack(enemy)

this is my code exactly and it runs till about halfway through then says its null and gets stuck on “self.attack(enemy)”

anyone know a solution? thanks! Screenshot - 98b1bcd5ec40dbb69be6e6f4ab2b9e5e - Gyazo

So i found a way around this and that would be to put the line “self.moveXY(23,23)” inside of the loop, however that dosent really fix the problem it just allowed me to beat the lvl. i will keep this post updated if i figure anything besides that out however i doubt it.

The clue is not in the cupcakes but in the error message. Your situation is similar to someone else’s right now, and Chronist Gilver has an explanation of the problem. Basically, you need to check whether there is an enemy before attacking; otherwise, your code tries to attack when there is no enemy and crashes.

Thank you for attempting to format your code correctly (while many do not at first and have to be asked to do so); however, for code, you highlight it and click the “</>” button, not the “quote” button (which is what I’m assuming you did).

One other thing: I’m pretty sure the “Bugs” tag is for problems in the game code. For problems in your own code, the post remains uncategorized (unless you are an adventurer or something).

Welcome to the CodeCombat forums! I wish you success in your endeavors!

Thanks for the reply, due to it telling me it was null over and over again i thought it was a problem with the game code, thats also why i posted this in the “bugs” category and as for the way to highlight code thanks! i had no idea and seen the quotes button and kinda just assumed. anyways thanks for the reply!

Hey Wizard,

You are not alone, I’ve had the same problem many times! Have to remember to check IF what you are trying to interact with(be it enemy, item, etc) exists, otherwise it returns as null.

Happy hunting, and coding!

I figured out what causes that code to crash and I still make that mistake every other level or so. :confused:

Get used to it! :grin:

Yeah, actually I think Woodland Cleaver is not designed to need an if enemy check, since there should always be enemies. Maybe you are killing them more quickly than we expected? What hero and gear are you using?