enemy = hero.findNearestEnemy()
while True:
hero.moveRight()
hero.moveUp()
hero.attack(enemy)
hero.attack(enemy)
For some reason it says this:
(Is the enemy still in sight?)
enemy = hero.findNearestEnemy()
while True:
hero.moveRight()
hero.moveUp()
hero.attack(enemy)
hero.attack(enemy)
For some reason it says this:
(Is the enemy still in sight?)
First, what hero and equipment are you using? Also, your goals are to survive, defeat three (3) ogres, navigate the maze, code under ten (10) statements, and collect the gems, not just to defeat the ogres.
Also, welcome to the CodeCombat Discourse! This is a cozy place where you can ask for help, get hints, and maybe just have fun! Before you proceed, please review this topic.
I know. The problem is that it doesn’t let me defeat the first ogre. Because it states that the orge isn’t in sight. The line it shows the error on is line 5 (hero.attack(enemy)).
My hero is Arrin. Equipment: A wooden shield, rusted armor, badly made glasses (the first ones), book N1, skin belt, normal sword, normal boots. (I’m sorry, I’m on russian and have to translate everything myself)
Here’s a photo:
OK found the issue. Move the hero.findNearestEnemy()
to right before the attacks. That should allow your hero to find enemies before the attacks, and it will run that command as often as needed, instead of once, like in your code.