I need help with leave it to cleaver [Solved]

this is my code Help me plzzzzzzzzzz

# This shows how to define a function called cleaveWhenClose
# The function defines a parameter called `target`
def cleaveWhenClose(target):
     
enemy = hero.findNearestEnemy()
        if hero.isReady("cleave"):
            hero.cleave(enemy)
           
        # else, just attack `target`!
           
        else:
            hero.attack(enemy)    

            

# 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("target")

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!

This is the only problem

you were close. Try to do if and else statements. Sort of like this

enemy = hero.findNearestEnemy()
        if hero.isReady("cleave"):
            hero.cleave(enemy)
           
        # else, just attack `target`!
           
        else:
            hero.attack(enemy)    

where do i put it ```

This shows how to define a function called cleaveWhenClose

The function defines a parameter called target

def cleaveWhenClose(target):
pass
# Put your attack code here
hero.attack(“target”)
ready = hero.isReady(“cleave”)
# If cleave is ready, then cleave target

    # else, just attack `target`!
    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(“target”)

``

At the top and bottem of your code.

Can you please do what I suggested, then come here with your new code(if it isn’t working).

No.
Get your old code again.
You have to watch for indentation.

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