Level: Leave it to Cleaver

Then its a equipment problem and again if it works delete the code.

ok thank you very much! have a good day

Hello again, it seems to be that my character is getting stuck in the entrance where the orges are coming from

OMG! THANK YOU!!!

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!

1 Like

Hello and welcome to code combat 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! btw the reason there is a pop-up when you type less than 20 characters is to prevent spam messages ( like someone just saying the letter e and clogging the discourses data.)

Hi There Guys,

I’m new here and only just joined. For leave it to cleaver code i can’t finish and there are only two more ogres left. Here is my code.

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

Some help please.

Hi Wiilli the target is supposed to be the enemy right?

Welcome to the forum! This is a family-friendly place where coders can share bugs, ask for help on any CodeCombat level (don’t forget to post your code correctly), or just hang out with other coders. But before you proceed, please check out our guidelines: this topic.
Have a great time! :partying_face:

Thanks that was really helpful for the code assistance :slight_smile:

Okay, so it says to put your attack code in, but instead you say hero.isReady. It says to attack, and then put in your ifReady part.

Thank you can you see what is wrong with my code please

1 Like

No wait, put your hero,cleave first, and then just attack the enemy like normal. I said it backwards.

1 Like

Thank you such a lot. i have been stuck on this for SOOO long. i have liked you.
:wink:

1 Like

Lol, no problem. Glad you past!

(;-J) thank u thank u

Wait a minute it doesn’t work, something is wrong and is not working

Oh. Can you post your revised code?

1 Like

What’s wrong with my code?

// This shows how to define a function called cleaveWhenClose
// The function defines a parameter called `target`
function cleaveWhenClose(target) {
    if(hero.distanceTo(target) < 5) 
        // Put your attack code here
        // If cleave is ready, then cleave target
        cleaveWhenClose();}
        // else, just attack `target`!
    else hero.attack(target);
// This code is not part of the function.
while(true) {
    var enemy = hero.findNearestEnemy();
    if(enemy) {
        // Note that inside cleaveWhenClose, we refer to the `enemy` as `target`.
        cleaveWhenClose(enemy);
    }
}

image

Wheres the bracket in this?

Major Hint
else {
hero.attack(target);
}

also, we cant just do this since this is not a method, and we havent finished the function yet.
so,

if (hero.isReady("cleave")) {
hero.cleave(target); 
}