# Leave it to cleaver again

**URL:** <https://discourse.codecombat.com/t/leave-it-to-cleaver-again/28894>\
**Category:** Level Help\
**Created:** [May 13, 2021, 5:58pm UTC](https://discourse.codecombat.com/t/leave-it-to-cleaver-again/28894 "2021-05-13T17:58:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ac3](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ac3/32/22375_2.png) [@ac3](https://discourse.codecombat.com/u/ac3)\
**Post date:** [May 13, 2021, 5:58pm UTC](https://discourse.codecombat.com/t/leave-it-to-cleaver-again/28894/1 "2021-05-13T17:58:36Z")

</div>

ok so i know i said that i fixed it but now he wont attack after he cleaves

```python
# 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
        hero.isReady
        hero.cleave(target)
        # else, just attack `target`!
        hero.attack(target)

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

```

---

<div class="post-metadata">

**Author:** ![ac3](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ac3/32/22375_2.png) [@ac3](https://discourse.codecombat.com/u/ac3)\
**Post date:** [May 13, 2021, 6:07pm UTC](https://discourse.codecombat.com/t/leave-it-to-cleaver-again/28894/2 "2021-05-13T18:07:10Z")

</div>

nvm i figured out that i needed to do

```python
else:

```

---

<div class="post-metadata">

**Author:** ![ac3](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ac3/32/22375_2.png) [@ac3](https://discourse.codecombat.com/u/ac3)\
**Post date:** [May 13, 2021, 6:15pm UTC](https://discourse.codecombat.com/t/leave-it-to-cleaver-again/28894/3 "2021-05-13T18:15:08Z")

</div>

ok so now that is out in the else he just sits up at the top and wont do anything for the rest of the time

```python
def cleaveWhenClose(target):
    if hero.distanceTo(target) < 5:
        pass
        # Put your attack code here
        # If cleave is ready, then cleave target
        hero.isReady
        hero.cleave(target)
    else:
        hero.attack(target)

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

```

---

<div class="post-metadata">

**Author:** ![Alexbrand](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Alexbrand](https://discourse.codecombat.com/u/Alexbrand)\
**Post date:** [May 13, 2021, 7:01pm UTC](https://discourse.codecombat.com/t/leave-it-to-cleaver-again/28894/4 "2021-05-13T19:01:26Z")

</div>

Hi again) Don’t want to be mean or rude, so, don’t take my words close to your heart. Just pay attention to the things I mention.

> [@ac3](#):
>
> `hero.isReady`

- The strangest part of the code.

> [@ac3](#):
>
> `if hero.distanceTo(target) < 5:`

Whar is this “target”? I dont see this variable definition.

> [@ac3](#):
>
> ```python
> if :
> # Note that inside cleaveWhenClose, we refer to the `enemy` as `target`.
> hero.isReady("cleave")
> 
> ```

Another one pretty unusual construction. It’s better to place operator `if` and condition in one line of code.

Also your while true loop almost duplicate cleaveWhenClose(enemy) function.

---

<div class="post-metadata">

**Author:** ![Alexbrand](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Alexbrand](https://discourse.codecombat.com/u/Alexbrand)\
**Post date:** [May 13, 2021, 7:02pm UTC](https://discourse.codecombat.com/t/leave-it-to-cleaver-again/28894/5 "2021-05-13T19:02:54Z")

</div>

> [@ac3](#):
>
> ```python
> if hero.distanceTo(target) < 5:
> pass
> 
> ```

I don’t think you really wanted to put `pass` there.
