Help with Village Warder Level[SOLVED]

Hi guys,

New to coding and new to Code Combat - no surprise. I am learning in Python and have had some issues with some of the levels but have always managed to troubleshoot my way through. Unfortunately I have hit a brick wall and simply cannot see what is wrong with the coding.

Firstly, I know the coordinates are slightly off - the left hand X should be 35, 34 however if I set it to that then a munchkin passes me and kills a villager before cleave strikes. The second coordinates for the right X should be 60,31 but I have put them slightly closer to the centre to try and offset the issue which is happening. Here is the issue:

findAndAttackEnemy does not appear to trigger when moving to the right side to fend off 1 munchkin. My hero ignores the munchkin that starts to attack the hero and then as the hero patrols back to the left side the munchkin attacks a villager and I fail the mission.

I have no issues with the coding for cleaving - which is odd as this is user created whereas the “findAndAttackEnemy” definition is already created and seems to be the definition I am having challenges with. I have reloaded and rewritten a few times but I cannot see what the issue is. Assistance PLEASE so I can learn and move on.

# This function attacks the nearest enemy.
def findAndAttackEnemy():
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)

# Define a function to cleave enemies (but only when the ability is ready).
def findAndCleaveEnemy():
    # Find the nearest enemy:
    enemy = hero.findNearestEnemy()
    # If an enemy exists:
    if enemy:
        # And if "cleave" is ready:
        if hero.isReady("cleave"):
            # It's time to cleave!
            hero.cleave(enemy)
    pass

# In your main loop, patrol, cleave, and attack.
while True:
    # Move to the patrol point, cleave, and attack.
    hero.moveXY(38, 34)
    findAndCleaveEnemy()
    findAndAttackEnemy()
    
    # Move to the other point:
    hero.moveXY(56, 30)
    # Use findAndCleaveEnemy function:
    findAndCleaveEnemy
    # Use findAndAttackEnemy function:
    findAndAttackEnemy

Thanks so much in advance!

and

Add a pair of parenthesis to the end of these two. Because functions will always have pair of parenthesis at the end.

Change this to 35,34

Change this to 60, 31

Lydia

That should just about do it. Don’t forget to solution her.

are none of you gonna welcome @BigJozzie

Hello and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!

Oh, great. can’t believe I forgot.

1 Like

Thanks so much for this. Parenthesis - totally missed them. I guess that’s what happens when you stare at something you’re not 100% on for long enough.

I would like to add that directing the hero to 35. 34 does fail the mission on the 2nd time returning to these coordinates as the bottom-most munchkin passes you and locks onto the lower-most villager, killing it before you get the cleave off.

Thanks so much once again. I am very impressed with the speed of response!

No problem! Glad I could help! Congrats on solving the level!
Lydia

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.