I need help with Munchkin Swarm. Here is my code. Where am i going wrong? My hero is getting killed and she does not seem to be attacking the chest either. Thank you.
var enemy = this.findNearestItem();
if (enemy){
var distance = this.distanceTo(enemy);
if (distance < 10){
if (this.isReady("power-up")){
this.powerUp();
} else {
this.attack(Chest);
}
}
}
// Check the distance to the nearest enemy.
// If it comes closer than 10 meters, cleave it!
// Else, attack the "Chest" by name.
}
i have also added a shield action. but my hero does not seem to be doing anything when i run my code. Please help. Here is my code with the Shield action. Thank you.
loop {
var enemy = this.findNearestItem();
if (enemy){
var distance = this.distanceTo(enemy);
if (distance < 10){
if (this.isReady("power-up")){
this.powerUp();
} else {
this.shield();
}
if(distance > 10){
this.attack(Chest);
}
}
}
// Check the distance to the nearest enemy.
// If it comes closer than 10 meters, cleave it!
// Else, attack the "Chest" by name.
}
Be sure to properly format your code as you type it, it makes it easier to spot any errors that may happen, for Javascript, you want to indent a line for every set of brackets it is in:
loop {
var enemy = this.findNearestEnemy();
if(enemy) {
// do something
} else {
var item = this.findNearestItem();
if(item.pos.x > 10) {
// do something else.
}
}
}
Take a moment to format your code so that things are intended based on how many brackets they are inside, and you might see the problem.