// 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 (target) {
hero.cleave(target);
} // else, just attack target!
}else {
hero.attack(target);
}
}
// 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);
}
}
Hi @Buddy_Dector, welcome to the CodeCombat discourse!
If you post your code on the forum please make sure it’s formatted. Read this topic to learn how to format your code: [Essentials] How To Post/Format Your Code Correctly
Then I’ll be able to read your code and help you.
Danny