[SOLVED] Backwoods Fork Level Help

I am extremely stuck

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

Maybe you again have to write if hero.isReady("cleave"):?

Also, maybe in def you have to write if enemy:?

Where do I put it at

Cleave? (20 characters)

This part when you said this

Can you send me the link? Also what is your problem for this level?
Lydia

Try: hero.cleave(target)
hero.attack(target)

It keep saying that I did not defeat all of the ogres but I did

It still says the same thing.

I noticed that in the while True loop, there is a space missing. So maybe correct that and submit again?
Lydia

It still does not work.

Try to write:

if hero.isReady("cleave")
    hero.cleave(target)

It works except the fact that I keep dying

Can you post your newest code? And can you send me the link to this level?
Lydia

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

# 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)
        hero.isReady("cleave")

It is called leave it to cleaver.

You have to write:

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

Maybe

else:
        hero.attack(target)
        # hero.shield()

And try to delete this part. (only here)

It should be

if (hero.isReady('cleave')):
            hero.cleave(target)

and then for the else
just write

else:
            hero.attack(target)

Delete this.

Lydia

1 Like