A Mayhem of Munchkins level help


I cant figure out how to finish A Mayhem of Munchkins. Could someone please tell me what I did wrong. Thank you
Here’s my code.

    enemy = self.findNearestEnemy()


while-True: should be while True:

Note that the game tips refer to the “while-true loop” in a programming language-agnostic manner. You have to use the proper syntax for your programming language of choice (while True: for Python, while (true) {} for JavaScript, etc.).


Thank you! I changed that and my hero doesn’t move or attack. He just stands there and gets swarmed and dies.
This is what i’m using now.

while True:
    enemy = self.findNearestEnemy()

Can you see whats wrong? I’m using Python.
Thank you again!


Please put triple backticks (```) before and after your code, so it is rendered properly (otherwise it is hard to see the indentation). I’ve formatted the code for you this time.

As for the code, it may be possible that self.findNearestEnemy() returns None, in case there is no enemy around. You should check if there is an enemy before you attack it:

    if (enemy):

Apart from that, make sure you have an weapon equipped. :wink:

while True:
    enemy = self.findNearestEnemy()
    if enemy:

Thank you so much for helping me. This is what I’m using now but I’m getting the same result. My hero does nothing and gets killed. Do you have any idea what I’m missing? I am using the triple back tic but when i post the message it wont show up.


if you tell me where in campain mode(dungon or the one after that) i can help you


Oh, I forgot to say the ``` should go on its own line. See the FAQ for an example or click in the pencil icon below your post to see the now-fixed code sample syntax.

As for the issue, it seems like you forgot to indent self.attack(enemy) further—it should be one level deeper than the if, so that it only gets evaluated when the if condition is true.


okay then…

while True:
    enemy = self.findNearestEnemy()
    if enemy:

I hope that is the right format. I’m using the tab key to indent. Is that right? If so the code is still not working. Also I am still using these ` it just wont show up. I am in Kithgard dungeon, mayhem of munchkins. My hero is still not doing anything. Thank you for your help!


Your indentation seems okay now—it usually doesn’t matter whether you use tabs or spaces, as the long as the indentation levels are correct.

Your code formatting looks okay now too, the ``` delimit code blocks so they are properly rendered (your code is now showing correctly).

I’m not sure—is there any error popup (message in a red box) showing up? What weapon and glasses do you have equipped?


In the CodeCombat level editor, make sure you actual code is indented using only tabs. Using a combination of tabs and spaces will not allow the instructions to be recognized as part of the loops. Go to options and turn on “show indent spaces” in CodeCombat


As far as I can see, CodeCombat’s code editor (Ace) automatically converts tabs to 4 spaces—you can’t indent with actual tabs (“hard tabs”) even if you wanted—, so that ultimately does not matter.

Make sure your indentation levels are properly aligned and everything should be okay. :wink:


the answer is simple ,just look here
while True:
enemy = hero.findNearestEnemy()

and the most important thing is that you should buy a pair of shoes to speed up and you will complete this level.


I had trouble too. This is how I passed it.

while True:
enemy =hero.findnearestenemy


Please do not revive dead threads or post solutions.