Leave it to Cleaver ....?

I’ve tried all the ones in the forums, and they don’t work.And I can’t seem to figure out what the code is. I’m using Python. Please help, this is the hardest level so far!

Can you please post your code?

1 Like

function cleaveWhenClose(target)
{ if(hero.distanceTo(target) < 5)
hero.attack(enemy);
// If cleave is ready, then cleave target
if(hero.isReady(“cleave”))
{ hero.cleave(target); }
else { hero.attack(target);

This does not look like Python. Either you’ve confused Python with JavaScript or you’ve just copy-pasted other solutions on the forum.
Also be sure to format your code according to the FAQ. When you are posting, there is an icon at the top that looks something like this:
</>
Click on it and then copy-paste your code.

hero.say("You'll get something like this.")
while True:
    hero.say("Of course, your indentations will still appear.")

Did you call cleaveWhenClose(target) in the loop?

1 Like

wheres the Faq? i dont see it.

See the icon that looks like </> ?
1 Like

it doesn’t work in Javascript, either.

Post your whole code. Maybe there is an error because you did not call the function in the loop.

1 Like

Where is that? i cant find it

When you type your post you can see at the top of the box thing that there is an icon that looks like that. Click on it and copy-paste your code.

1 Like

I’m not too good with JavaScript so I might not be able to help, but I can try:

// 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
        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) {
    var enemy = hero.findNearestEnemy();
    if(enemy) {
        // Note that inside cleaveWhenClose, we refer to the enemy as target.
        cleaveWhenClose(enemy);
    }
}

It says:
Expected an identifier and instead saw “if”.
???

Thanks so much! It worked!

Sorry for all the trouble, Python is so much easier to me than JavaScript, but yeah, happy to help! :smiley:

2 Likes

Hellenar, if you have given out the code to Mokeygail, please try not to do so in the future. It makes it easier for users to just get the code for the level, and pass it, without learning anything.

Thanks!

Thank you @Luke10. I will bear that in mind in the future. :slight_smile:

Correct code also redacted.

1 Like

Fine. There are YouTube videos. Will you redact that too?

Or you could leave and let me play in peace.