Leave it to Cleaver ....?


#1

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!


#2

Can you please post your code?


#3

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


#4

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?


#5

wheres the Faq? i dont see it.


#6
See the icon that looks like </> ?

#7

it doesn’t work in Javascript, either.


#8

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


#9

Where is that? i cant find it


#10

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.


#11

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);
    }
}

#12

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


#14

Thanks so much! It worked!


#15

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


#16

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!


#17

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

Correct code also redacted.


#18

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


#19

Or you could leave and let me play in peace.


#20

I looking for the solution for this step and actually spent my time almost 3 days to get the solution and read many forum on this issued, finally I got the solution for my problem and here is the answer (using 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 and hero.isReady(“cleave”):
pass
# Put your attack code here
# If cleave is ready, then cleave 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)

Many player difficult or not alert on that script that I bold. May this can help others.