Leave it to cleaver,,, pls help


ok so im trying to do this and i cant figure it out, why is he not doing the regular attack and he just stops and does nothing

There is already a topic for this so can you please put this there. And when you do, can you also format your code? Thanks!

how do i format my code

Hi and welcome)
You need to add conditions and else at least. Also it’s better to format your code in the post as far as it gives people simple way to help you with your code.

P.S. And i would reccommend not to show your e-mail on the Internet without extra need.

You use this button </>

what do u mean ¨conditions and else¨

This is the topic you can post your code in.

In function you defined commented instructions tell you to do so. Like

if I am hungry:
    eat
else:
    drink a cup of tea
1 Like

so like this

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

i still dont see what part of it is wrong though

Do you need the pass there?

i dont know what you mean by that

I just feel like the pass you wrote after def cleaveWhenClose (target): if hero.distanceTo (target) < 5: isn’t helpful

ok im just trying to figure out how to complete this level man, i have to get this entire world done before tomorrow for a grade.

1 Like

Pass means stop.

Looks like you dont understand operators and synthax importance) They help you to write your code logic.

The goal of the code is to write a function with certain conditions. Is distance to enemy close enough, can your hero use cleave or only attack and so on.

Your also not saying if hero.isReady
hero.cleave (target)

where would i put that

Directly above your hero.cleave

it still doesnt work

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)
^

type or paste code here