I need help in “stillness in motion” . Here is my code. when i run this code it says that " this.shield();" is not a function. and my hero dies. What am i doing wrong? Please help. Thank you.
var enemy = this.findNearestEnemy();
// If there is an enemy, then...
if(enemy) {
var distance = this.distanceTo(enemy);
// Create a distance variable with distanceTo.
// If the distance is less than 5 meters, then attack.
if(distance < 5){
this.attack(enemy);
}
// Else (the enemy is far away), then shield.
else{
this.shield();
}
// Else (there is no enemy)}...
} else {
// ... then move back to the X.
this.moveXY(40, 34);
}
}