Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

[SOLVED] Leave It To Cleaver [Help]


#1

Hi Guys, feeling a bit stuck with this level. Please can you give me feed back on the below code.

Thanks :slight_smile:

# This shows how to define a function called cleaveWhenClose
# The function defines a parameter called `target`
def cleaveWhenClose(target):
    if hero.distanceTo(target) < 5:
        pass
        # Put your attack code here
        # If cleave is ready, then cleave target
        if hero.isReady:
            hero.cleave(target)
        # else, just attack `target`!
        else:
            hero.attack(target)

# This code is not part of the function.
while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        # Note that inside cleaveWhenClose, we refer to the `enemy` as `target`.
        cleaveWhenClose(enemy)


#2

You haven’t specified what’s it’s checking. Replace it with if hero.isReady("cleave"):


#3

Thank you. Don’t know how I missed that.