Clash of Clones level help

while True:
    enemy= hero.findNearestEnemy()
    if hero.health < 50:
        hero.moveXY(34, 35)
    else:
        if enemy:
            hero.bash(enemy)
            hero.attack(enemy)
            hero.attack(enemy)
    

Hi I need some help on clash of clones level. I have been stuck on this for more than a year and have constantly been looking at help for this level. I finally decided to post this rather simple code. The problem with this is that for some reason, my hero starts saying “But it’s Dead” in the middle and dies.

The combination of these three lines is causing the problem. You have identified one enemy, and at some point before the last attack the enemy dies, but your code is telling your hero to attack. Since there isn’t an enemy, your hero says “But it’s Dead”.

        if enemy:
            hero.bash(enemy)
            hero.attack(enemy)
            hero.attack(enemy)

Also, the Bash has a Cooldown period of 6 seconds which means you can’t use it until the time is up. With no check on the cooldown like if hero.isReady("bash"): your hero waits until the 6 seconds is up to continue the code. If the hero isn’t ready, do a regular attack or shield.

Thanks for that, now i added some code and the hero kills everyone, but then he goes off chasing a Yak and gets killed, please help me here.

hero.cast("invisibility", hero)
hero.moveXY(83, 67)
while True:
    enemy= hero.findNearestEnemy()
    if hero.health < 50:
        hero.cast("invisibility", hero)
        hero.moveXY(34, 35)
    else:
        if enemy:
            if hero.isReady("bash"):
                hero.bash(enemy)
            else:
                if hero.isReady("cleave"):
                    hero.cleave(enemy)
                else:
                    hero.attack(enemy)

The starting code is to get behind the archers and slaughter them

Nevermind, thank you for your help, I managed to get the level done.

1 Like

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