So I am having trouble doing the code can I get some help

Welcome to the forum @kayden4444 :tada: let’s see if I can help you… :thinking:

2 Likes

first of all can you post your code?

2 Likes

yes

// 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
var ready = 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);
}
}

my bad
I am new sorry

image

1 Like

can you do this? 20000 char

1 Like

and can you send me the link?

1 Like
// 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
        var ready = 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);
    }
}

The link of what???
If you mean the link of codecombat I am using the app.

CoCo has an app? 20 char

1 Like

yay for chrome. it’s nice and and good to see what they have me do.

then what world is it? (kithgaurd dungeon etc.)

1 Like

of it’s backwoods forest level 15.

ok lets see 20 characters

1 Like

Here’s the link: https://codecombat.com/play/level/leave-it-to-cleaver

your first problem is

It shouldn’t be a variable it should be an If

2 Likes
function cleaveWhenClose(target) {
    if(hero.distanceTo(target) < 5) {
        // Put your attack code here
        // If cleave is ready, then cleave target
        if (enemy) {
            var ready = hero.isReady("cleave");
        hero.cleave(enemy);
        }
        // else, just attack `target`!
        else {
            hero.attack(enemy);
        }
    }
}
it still won't let me attack the ogres

no it should be 20 char

if hero.isReady("cleave");
2 Likes