Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Level: Munchkin Swarm

I’ve been working on this level for a while now and I used the code that was showed on the help but it didn’t work. I’ve cheked the code multiple times and it’s right but it’s not doing what it’s suppose to.

If you are still stuck on this, you need to post your code so someone can find the error you can’t.

here is my code for the level i need help. Im using PYTHON

loop:
    enemy = self.findNearestEnemy()
    
    if self.distanceTo(target)<10:
        if self.isReady("cleave"):
            self.cleave(enemy)
        if not self.isReady("cleave"):
            self.shield()
            
    if enemy >10:
        self.attack("Chest")

Can you fix it so the indenting is right?
as it is right now you have an empty “loop:” since there is nothing indented right after it.

next you set “enemy” but check the distanceTo target. It is confusing sometimes that some commands default to enemy and other default to target.

1 Like
 loop: 
        enemy = self.findNearestEnemy()    
        enemydistance = self.distanceTo(enemy.pos)
    if self.isReady("cleave"):
            if enemydistance < 10:
        self.cleave(enemy)
    else:
            self.attack(chest)
       pleas help it probably with the else part (at lest thats what it says)

Please read the FAQ before posting…

I put the ``` around your code so we can see how you indented your code…

Python uses indents to keep track of what goes with what (scope) and your indents are all over the place.

Please even them up, otherwise neither Python nor us, can tell what you had in mind…

loop:
    enemy = self.findNearestEnemy()
    enemydistance = self.distanceTo(enemy.pos)
    if self.isReady("cleave"):
        if enemydistance < 10:
            self.cleave(enemy)
    else:
        self.attack(chest)

I am assuming that this is what you actually meant…

try with it indented like you mean, and see what happens. :smile:

Could you help, and tell me where to put is.ready (“Cleave”)

if self.distanceTo(enemy) < 10 and self.isReady("cleave"):

can someone help

[en_US.composer.my_buttons_text]

so when i want them to cleave it wont

while True:
# Check the distance to the nearest enemy.
nearestEnemy = hero.findNearestEnemy()
distance = hero.distanceTo(nearestEnemy)
# If it comes closer than 10 meters, cleave it!
enemy = hero.findNearestEnemy()
enemydistance = self.distanceTo(enemy.pos)
if hero.isReady(“cleave”):
if enemydistance < 10:
hero.cleave(enemy)
else:
hero.attack(“Chest”)
hero.attack(“Chest”)
# Else, attack the “Chest” by name.

pass