I recently beat the level, “A Bolt in the Dark”, and I ran into an issue where Tharin would kill the first enemy in the first room, and then move into the next room. However, instead of attacking the second enemy, it would attempt to move through the left wall to the first enemy Tharin already killed.
Solution:
var enemy = this.getNearestCombatants(); needed to be declared within the scope of the loop:
loop {
var enemy = this.getNearestEnemy();
this.attack(enemy);
this.attack(enemy);
//etc.
}
declaring the variable (enemy) outside of the loop will cause .getNearestCombatants() to reference whichever object was closest at the time it was called, and we want it to evaluate who is closest each time we loop.
Tharin otherwise might bump into a wall while the loop executes but it didn’t seem to break. There seems to be just enough time to finish the level. Is there any way that variable scope might be mentioned in the level guide?