Eagle Eye (Backwoods Forest) Problem


#1

The level says to change something in line 7, but anything I try doesn’t work, including what it suggests in help which is hero.shouldAttack(target). I also don’t see how hero.shouldAttack can help me because I can’t attach(target) to it or else it says that hero.shouldAttack isn’t a function, which I don’t get. Further, I don’t understand how I can specify that Burls are different than Ogres if they aren’t named. Please help! Is this a bug?


#2

Theres is a function findByType(type,units) you can use in conjunction with
findEnemies() to differenciate the two unit types if you have good enough glasses


#3

@Catsync: indeed there seems to be an issue with the shouldAttack() method, please check:


#4

Hi! Could you please share which glasses? I have the Crude Glasses.


#5

Hi! Have you heard anything back?


#6

Hey! Thanks for the bug report. :slight_smile:

I can’t reproduce this bug. Can you try clearing cache, and also playing the level on direct.codecombat.com? It could be a cacheing issue, since I recently changed it from isOgre to shouldAttack.


#7

I’m 100% stuck on this level. Can someone post the solution here? Not sure what I’m doing wrong.


#8

It’s better if you post your solution and we’ll try to help you.


#9

I am also experiencing some problems with my code.

This baby griffin will help you spot Ogres!

while True:
target = hero.findNearestEnemy()
# Some of the targets will be Burls. You don’t want to attack them!
# Use this to tell if you should attack: hero.shouldAttack(target)
if target:“ogre” # ∆ Change this!
if hero.shouldAttack(target)
hero.say(“Target is an ogre!”)

I would definitely appreciate some help.

Thank you


#10

Could you post your code as code with formating? For Python indents are very important and it’s hard to read it in that view as you posted it.


#11

Awesome thanks Bryukh. So I’m going through this with my son (he’s 9 yrs old) and this is the only one we’re stuck on so far. Here’s what one of our solutions have looked like. I feel like we’ve tried everything but nothing is working. Any help is appreciated. Thanks again.


#12
if target: ogre

It’s a wrong line.

You need to check whether the target is an ogre or not with the shouldAttack function.

if hero.shouldAttack(target):
    hero.attack(target)

Don’t forget about indents - they define code blocks and the order of running.


#13

Still lost, haha. I’ve tried for like an hour :open_mouth:


#14

Please post your updated code if you still need help. :slight_smile:


#15

I was stuck on this for literally hours and finally figured it out!
OK first make sure you have the right equipment equipped! Because I couldn’t use the hero.attack command :/. That was my first error cause i didn’t even have a sword to attack with.

Also I dont want to give you the answer but ill give you a better clue because I dont think the hints really help that much tbh.
Ogre = hero.findNearestEnemy()
thats the first line.


#16

I’ve got the following code, and somehow passed, but I have a couple questions that I could use some clarification on:
while(true) {
var target = hero.findNearestEnemy();
if (hero.shouldAttack(target)) {
hero.attack(target);
}
}

Here are my questions:
so the ‘var target’ line basically says to identify the nearest object and assign it the variable “target”, this makes sense, but then in the rest of the code, I’ve never specified that burls are bad to attack and ogres are good to attack. Why did this code work?

with the last two lines starting with ‘if’ aren’t I basically saying “if the hero should attack a target, then attack the target”, but I’m saying this without specifying whats true or false. I had been trying variations of if target:ogre and couldn’t get anything to work.

If anybody can help me understand why my code worked without me seeming to specify which variables I wanted attacked, it would help my understanding tremendously.


#17

The shouldAttack(target) function determines for you whether or not you should attack that particular target. It returns true if it’s an ogre, and false if it’s a burl.

shouldAttack() is a special helper function to make the code a little simpler in this level. Later levels, and some premium levels, will show how to figure the target’s type manually.

Spoiler alert: you can use if target.type == "burl", but many players were confused by t his type of if statement if we used them this early in the campaign, so we tried something simpler. :slight_smile:


#18

I think its a good level but people think they can already define which type to attack but you cant, maybe would of been easier to have .type in.

I tried to use the .type but that didnt work for me apparently you need some type of different glasses.
Thing is try to ignore the errors that pop up because sometimes they still pop up even when your actually right, tbh Id ignore the griffin all together I dont know why they put that in, i think its just to tell you the difference between enemies. Thats where it confused me ill give you now the second line of code if hero.shouldAttack(Ogre): # ∆ Change this! also this is written in python.

Question 1: Just remember those code written underneath that you dont see, as this is a tutorial so dont over-complicate it and refer to the things at the bottom there more helpful than u think.

Question 2: by putting ‘if’ you are asking to the program see whats TRUE or FALSE.

I hope this helps. Basically try not to over complicate it for yourself because at this point your still using someone else’s code underneath.


#20

You can also just see if the target is a burl and if it is, don’t attack it. Meaning you don’t have to redo the if statement, you just have to add on to it.


#21

Hey Bryukh!
I’m stuck on the same level as everyone else here. Can you check my code?

while True:
target = hero.findNearestEnemy()
# Some of the targets will be Burls. You don’t want to attack them!
# Use this to tell if you should attack: hero.shouldAttack(target)
if hero.shouldAttack(target) :
hero.say(“Target is an ogre!”)
hero.attack(target)