The Final Kithmaze help


#41

I’ve been trying to figure out how to do this for like 10 minutes, and I can’t seem to figure out how. I’m using Javascript. Here’s my code:

var enemy = hero.findNearestEnemy();

while (true) {
     hero.moveRight();
     hero.moveUp();
     hero.moveRight();
     hero.moveDown(2);
     hero.moveUp();
     hero.enemy;
     hero.attack(enemy);
     hero.attack(enemy);
}

I’ve tried sticking this part in all the different spots I can think of, but it always runs the code early, and it says that there isn’t an enemy in my line of sight.

     hero.enemy;
     hero.attack(enemy);
     hero.attack(enemy);

Am I doing something wrong, or is the game bugging out?


#42

Please format your code according to the FAQ. It makes it easier to understand your code.
your are missing I think if enemy in that.


#43

Please tell us more about whats wrong. Also post this with your code. Remember to format your code according to the FAQ.


#44

You are finding the nearestEnemy before even moving once.

When the function is called, that is when the nearestEnemy is assigned to the variable enemy.

So instead of hero.enemy you want to do var enemy = hero.findNearestEnemy();.


#45

the enemy=self.findnearestenemy() dont
work at alllllllllllllllllll!!!:smiling_imp:


#46

Are you using correct capitalization and spelling? Provide an instance in which enemy = hero.findNearestEnemy() does not work.


#47

Please do not spam with exclamation marks. It does not help us as the consultant.

You need to capitalize every new word in self.findNearestEnemy

So its find Nearest Enemy() like what I wrote above. Also, if you are using java script, you must use this.findNearestEnemy instead of self


#49

Please do not post the working code. Even though you completed it, somebody could get it. The point of this game is to help kids to learn to code through a game, but not to just give them the code. But good job with the level!


#50

im using lua and ive been stuck for a month


#51

@Peter_Fisher I would help but i have no idea how to use lua. it looks complicated. Sorry :confused:


#52

Sorry about that!!!