Leave It To Cleaver [Help]

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)

1 Like

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

1 Like

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

Hello,
Is it possible to further explain what is going on in this code. I have understood everything so far, but this code is not making any since to me.

thanks,

hero.isReady() is a function that returns a boolean.

  • A boolean is either a True or a False.
  • So the function isReady() is a function within the class hero, so in pseudocode,
def isReady(action):
    if action's cooldown is over:
        return True
    else:
        return False

So calling if hero.isReady("cleave"): checks if the player can perform the action “cleave”, and if it returned True, then the player can cleave.

thank you for the help @Chaboi_3000

def cleaveWhenClose(target):
if hero.distanceTo(target) < 5:
pass
# Put your attack code here
# If cleave is ready, then cleave target
if hero.isReady(“cleave”):
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)

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!

Please format your code, then we will help you.

#side-note
removed [SOLVED] as the discussion continues

Can someone please help me wit this level I don’t understand what is going wrong.
Screenshot 2021-05-07 10.09.00 AM

uhhhhmmmmmm :flushed: How???

let’s discuss that in PM, i sent you