The Final Kithmaze

I’m trying to make a loop to get all the way through the maze. Help?

What have you tried so far?

I tried this:
this.moveRight();
this.moveUp();
this.attack(“Blorp”);
this.attack(“Blorp”);
this.moveRight();
this.moveDown();
this.moveDown();
this.moveUp();
this.moveRight();
this.moveUp();
this.attack(“Bop”);
this.attack(“Bop”);
this.moveRight();
this.moveDown();
this.moveDown();
since the loop wouldn’t work, but i didnt realize how long the maze was, so it would take more lines of code than a loop would.

You’ll need to use a variable to attack the nearest enemy at each step of the maze where you run into line of sight of an ogre. That’s how you can use a loop to do it. You don’t need to know an enemy’s name to attack it when you use a variable, so each iteration of the loop can be the same.

var enemy = this.getNearestEnemy();
this.attack(enemy);

I tried the code given:

var enemy = this.getNearestEnemy();
this.attack(enemy);

However, it does not work! Going the long way is the only way for me to beat the level.

@Tamer The code should work if it’s inside a loop with the right movement commands (and two attack commands per loop, since enemies take two hits). What kind of problems did you see that made it not work?

I am seeing this issue in Clojure too, when adding the following code inside a loop:

(let [enemy (.findNearestEnemy this)]
         (.attack this enemy)
         (.attack this enemy)
)

It only executes the move sentences and ignores the attack ones.

@Crackers Do you find the enemy when you are in visual range of it, or is it behind a wall? It will store a nil value in the enemy variable if findNearestEnemy has line of sight blocked when you call it.

It is inside my visual range, the code did work on other languages though.

I saw this happening on other levels, for example on the one you have to plant bombs and patrol an area, only on clojure I had a problem where the character would only move and never plant the bombs.

It happened to me too, i had to write (.attack this (.findNearestEnemy this)) every time, but to be honest it seems like a bug to me

I’ve opened a bug issue here to track this one: https://github.com/codecombat/aether/issues/124

Same here. The let statements are ignored inside a dotimes.

i need help on this level the final kithmaze

Hi, welcome to Codecombat discourse!
Could you please tell us what your issue is as well as the underlying code?
(Ctrl+Shift+C and paste it)

this.moveRight();
this.moveUp();
this.attack(“Blorp”);
this.attack(“Blorp”);
this.moveRight();
this.moveDown();
this.moveDown();
this.moveUp();
this.moveRight();
this.moveUp();
this.attack(“Bop”);
this.attack(“Bop”);
this.moveRight();
this.moveDown();
this.moveDown();

Okay, but what’s your problem?