Suar
October 15, 2021, 10:32pm
1
Hi! Please assist! My Hero doest cleave. The code is right. What
s 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!
3 Likes
Vanessa
October 16, 2021, 12:28am
3
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.
Suar
October 16, 2021, 2:48pm
4
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?
Suar
October 17, 2021, 10:37am
7
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”.
Aya
October 17, 2021, 11:47am
8
Try indenting the lines, also, can you please post your gear, you might’ve forgot to equip the sword with cleave ability.
Suar
October 17, 2021, 12:01pm
9
“Try indenting the lines,” - it`s already done.
Here is my gear:
Aya
October 17, 2021, 12:28pm
10
Try equipping this sword instead:
Suar:
it`s already done.
It doesn’t show in your posted code
Vanessa
October 17, 2021, 1:48pm
11
I think that’s only for python with the indents.