This below formula works:
function cleaveWhenClose(target) {
if(hero.distanceTo(target) < 5) {
if (hero.isReady(“cleave”))
hero.cleave(target);
// else, just attack target!
} else {
hero.attack(target);
}
}
while(true) {
var enemy = hero.findNearestEnemy();
if(enemy) {
cleaveWhenClose(enemy);
}
}
but I tried to keep things simple by changing parameter name to enemy like the codes below. It doesn’t work. Why not?
function cleaveWhenClose(enemy) {
if(hero.distanceTo(enemy) < 5) {
if (hero.isReady(“enemy”))
hero.cleave(enemy);
// else, just attack target!
} else {
hero.attack(enemy);
}
}
while(true) {
var enemy = hero.findNearestEnemy();
if(enemy) {
cleaveWhenClose(enemy);
}
}
Luke10
March 31, 2017, 3:59pm
2
I’m not sure that is a actual command…
if (hero.isReady(“enemy”))
hero.cleave(enemy);
// else, just attack target!
} else {
You missed a bracket
Not sure if I understand what you mean, do I NEED to keep the
"function cleaveWhenClose(target) {"
for it to be a proper command?
Why can’t I change the variable (target) into the variable (enemy)?
“function cleaveWhenClose(enemy) {”
Luke10
April 2, 2017, 12:40pm
5
Ok, never mind about that
@kasakuri You can. JavaScript is about variable and dynamic coding. There are a few problems with your code I believe. The first is in my previous comment, you missed a bracket. Also I noticed in your second one, you wrote:
if (hero.isReady("enemy"))
Shouldn’t it be:
if (hero.isReady("cleave"))
1 Like