Munchkin-harvest

Hi! Please assist! My Hero doest cleave. The code is right. Whats the problem?

Here is my code:

while(true) {
var enemy = hero.findNearestEnemy();
if(enemy){
if (hero.isReady(“cleave”)) {
hero.cleave(enemy);
} else {
hero.attack(enemy);
}
}
}

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:

3 Likes

You need to change the order of the brackets to something like this:

if (cat) {

if(self.isReady(”hug”)) {
self.hug(cat);
 }
  }
else {
self.attack(siblings);
}

Notice the if brackets came before the else statement.

Thank you Vanessa!

I tried. But it does`not work(((

while(true) {
var enemy = hero.findNearestEnemy();
if(enemy){
if (hero.isReady(“cleave”)) {
hero.cleave(enemy);
}
} else {
hero.attack(enemy);
}

}

Will you post your code using the </> button? This way it’s easier to read. Thanks!

1 Like

Huh. The code should be working. @moonwatcher348 do you know what’s the problem with this?

I tried this:



while(true) {
var enemy = hero.findNearestEnemy();
if(enemy){
if (hero.isReady(“cleave”)) {
hero.cleave(enemy);
}
}
else {
hero.attack(enemy);
}
}

This

while(true) {
var enemy = hero.findNearestEnemy();
if (hero.isReady(“cleave”)) {
hero.cleave(enemy);
}
else {
hero.attack(enemy);
}
}

And this

while(true) {
var enemy = hero.findNearestEnemy();
if(enemy){
if (hero.isReady(“cleave”)) {
hero.cleave(enemy);
}
else {
hero.attack(enemy);
}
}
}


Always Hero only attack the enemy without “cleave”.

Try indenting the lines, also, can you please post your gear, you might’ve forgot to equip the sword with cleave ability.

“Try indenting the lines,” - it`s already done.

Here is my gear:

Try equipping this sword instead:

It doesn’t show in your posted code

I think that’s only for python with the indents.

Alright… (20characters)