# Hunting Party, possible bug or operator error?(python)

**URL:** <https://discourse.codecombat.com/t/hunting-party-possible-bug-or-operator-error-python/8406>\
**Category:** Bugs\
**Created:** [July 15, 2016, 12:36pm UTC](https://discourse.codecombat.com/t/hunting-party-possible-bug-or-operator-error-python/8406 "2016-07-15T12:36:32Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Garrett\_Campen](https://avatars.discourse-cdn.com/v4/letter/g/ac91a4/32.png) [@Garrett\_Campen](https://discourse.codecombat.com/u/Garrett_Campen)\
**Post date:** [July 15, 2016, 12:36pm UTC](https://discourse.codecombat.com/t/hunting-party-possible-bug-or-operator-error-python/8406/1 "2016-07-15T12:36:32Z")

</div>

# command troops to move east and attack any ogre they see

#use for-loops and findFriends  
#you can use findNearestEnemy() on your soldiers to get their nearest enemy

loop:  
friends = self.findFriends()  
friend = self.findNearest(friends)  
enemies = friend.findEnemies()  
enemy = friend.findNearest(enemies)  
for friend in friends:  
if enemy:  
self.command(friend, “attack”, enemy)  
if not enemy:  
self.command(friend, “move”, {“x”: friend.pos.x + 10, “y”: friend.pos.y})

certainly not a code i would make just happened to be the last go around i was on. my indents are correct, just not sure how to show that on here.

I’ve read that find nearest shouldn’t be added to this code, but the code above was the only python code i could find for this level that wasnt completely terrible. His problem being his troops did nothing but run east. This is the 5th code chunk ive used and modified everyway i could think [of.At](http://of.At) this point im just looking for anyprogress past a red circle and the SAME FLIPPIN ERROR! All times i’ve deleted everything and tried fresh changing Variables,moving units 1 at a time, in groups, and all at once, using others broken code(This is a broken code-im rather sure i was able to fix his mistake, and once past the refference error im gravy).

This codes INTENDED goal is: -Create variable for an array of all friends.  
-For each friend in the array stored in friends  
-if there is an enemy-attack it  
-if not an enemy - move x+10  
-start over till no friend  
im curious on if this needs an index or not but i can solve that myself later.

PROBLEM: the problem on every single time I run “friends = hero.findFriends()” no matter where its at or what its in, i get “ReferenceError: profile is not defined”

im not trying to define any new functions - im making a variable with a value.  
It’s not an item issue, i’ve got the top glasses i can and the findFriends command is in its list.  
What i dont understand, is how every other code ive looked at start with that variable combo somehow/someway/somewhere no matter what. Even tried it as " for friend in self.findFriends():"

Appreciate any feedback, because im completely struck. GL mates

---

<div class="post-metadata">

**Author:** ![Neel\_Sharma](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@Neel\_Sharma](https://discourse.codecombat.com/u/Neel_Sharma)\
**Post date:** [July 15, 2016, 12:45pm UTC](https://discourse.codecombat.com/t/hunting-party-possible-bug-or-operator-error-python/8406/2 "2016-07-15T12:45:12Z")

</div>

Could you please format your code according to the [Discourse FAQ](http://discourse.codecombat.com/faq)? It would help out a ton. You just have to put three backticks around your code.

---

<div class="post-metadata">

**Author:** ![Garrett\_Campen](https://avatars.discourse-cdn.com/v4/letter/g/ac91a4/32.png) [@Garrett\_Campen](https://discourse.codecombat.com/u/Garrett_Campen)\
**Post date:** [July 15, 2016, 12:47pm UTC](https://discourse.codecombat.com/t/hunting-party-possible-bug-or-operator-error-python/8406/3 "2016-07-15T12:47:34Z")

</div>

```python
# command troops to move east and attack any ogre they see
#use for-loops and findFriends
#you can use findNearestEnemy() on your soldiers to get their nearest enemy
loop:
    friends = self.findFriends()
    friend = self.findNearest(friends)
    enemies = friend.findEnemies()
    enemy = friend.findNearest(enemies)
    for friend in friends:
        if enemy:
            self.command(friend, "attack", enemy)
        if not enemy:
            self.command(friend, "move", {"x": friend.pos.x + 10, "y": friend.pos.y})

```

---

<div class="post-metadata">

**Author:** ![Neel\_Sharma](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@Neel\_Sharma](https://discourse.codecombat.com/u/Neel_Sharma)\
**Post date:** [July 15, 2016, 12:49pm UTC](https://discourse.codecombat.com/t/hunting-party-possible-bug-or-operator-error-python/8406/4 "2016-07-15T12:49:11Z")

</div>

First of all, don’t actually define friend because you do that in the for loop and second of all I believe it was the same error as in [this topic](https://discourse.codecombat.com/t/referenceerror-profile-is-not-defined-python/8404/5). I reccommend hanging in there until the problem is solved, which at max may take around a day.

---

<div class="post-metadata">

**Author:** ![Garrett\_Campen](https://avatars.discourse-cdn.com/v4/letter/g/ac91a4/32.png) [@Garrett\_Campen](https://discourse.codecombat.com/u/Garrett_Campen)\
**Post date:** [July 15, 2016, 12:59pm UTC](https://discourse.codecombat.com/t/hunting-party-possible-bug-or-operator-error-python/8406/5 "2016-07-15T12:59:01Z")

</div>

not to be off topic, but can I ask why I would do it inside the for and not before it? how is it suppose to know what “friend” & “friends” are, wouldnt that be telling it the same thing as

```python
for some_word_no_ones_ever_heard in some_array_that_doesnt_exist

```

they aren’t very user friendly in terms of explaining much of anything at all lol

---

<div class="post-metadata">

**Author:** ![Garrett\_Campen](https://avatars.discourse-cdn.com/v4/letter/g/ac91a4/32.png) [@Garrett\_Campen](https://discourse.codecombat.com/u/Garrett_Campen)\
**Post date:** [July 15, 2016, 1:00pm UTC](https://discourse.codecombat.com/t/hunting-party-possible-bug-or-operator-error-python/8406/6 "2016-07-15T13:00:55Z")

</div>

ouch, well thats minorly depressing 😕 how do i get my geek on now? Lol

---

<div class="post-metadata">

**Author:** ![Neel\_Sharma](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@Neel\_Sharma](https://discourse.codecombat.com/u/Neel_Sharma)\
**Post date:** [July 15, 2016, 1:01pm UTC](https://discourse.codecombat.com/t/hunting-party-possible-bug-or-operator-error-python/8406/7 "2016-07-15T13:01:18Z")

</div>

Simply because friend is a unit in the array friends. So when you use a for loop, you take out that friend and tell it what to do from the for loop.

---

<div class="post-metadata">

**Author:** ![Garrett\_Campen](https://avatars.discourse-cdn.com/v4/letter/g/ac91a4/32.png) [@Garrett\_Campen](https://discourse.codecombat.com/u/Garrett_Campen)\
**Post date:** [July 15, 2016, 1:09pm UTC](https://discourse.codecombat.com/t/hunting-party-possible-bug-or-operator-error-python/8406/8 "2016-07-15T13:09:36Z")

</div>

ah well yeah, ok, i see what you’re saying I think. in the 1st 4 lines after loop?  
went though so many options i was game to try anything haha. fixed other persons error and hit run…I would have only put friends = hero.findFriends() then on to for loop

---

<div class="post-metadata">

**Author:** ![Garrett\_Campen](https://avatars.discourse-cdn.com/v4/letter/g/ac91a4/32.png) [@Garrett\_Campen](https://discourse.codecombat.com/u/Garrett_Campen)\
**Post date:** [July 15, 2016, 1:11pm UTC](https://discourse.codecombat.com/t/hunting-party-possible-bug-or-operator-error-python/8406/9 "2016-07-15T13:11:00Z")

</div>

and it must be a bug because i changed glasses, changed up code and same error, just on enemy this time…

```python
enemy = hero.findNearest(hero.findEnemies())
hero.moveXY(60, 72)
if enemy:
    hero.attack(enemy)
else:
    pass

hero.moveXY(64, 24)
if enemy:
    hero.attack(enemy)
else:
    pass

hero.moveXY(88, 60)
if enemy:
    hero.attack(enemy)
else:
    pass

```

---

<div class="post-metadata">

**Author:** ![nick](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/nick/32/784_2.png) [@nick](https://discourse.codecombat.com/u/nick)\
**Post date:** [July 15, 2016, 3:34pm UTC](https://discourse.codecombat.com/t/hunting-party-possible-bug-or-operator-error-python/8406/10 "2016-07-15T15:34:22Z")

</div>

Thanks for the details–I found the bug. Should be fixed now, if you try again. (You may need to clear your browser cache.)

---

<div class="post-metadata">

**Author:** ![Garrett\_Campen](https://avatars.discourse-cdn.com/v4/letter/g/ac91a4/32.png) [@Garrett\_Campen](https://discourse.codecombat.com/u/Garrett_Campen)\
**Post date:** [July 15, 2016, 5:28pm UTC](https://discourse.codecombat.com/t/hunting-party-possible-bug-or-operator-error-python/8406/11 "2016-07-15T17:28:29Z")

</div>

appreciate it buddy ty =]

---

<div class="post-metadata">

**Author:** ![Neel\_Sharma](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@Neel\_Sharma](https://discourse.codecombat.com/u/Neel_Sharma)\
**Post date:** [July 16, 2016, 5:20pm UTC](https://discourse.codecombat.com/t/hunting-party-possible-bug-or-operator-error-python/8406/12 "2016-07-16T17:20:07Z")

</div>

no problem dude 😀

---

<div class="post-metadata">

**Author:** ![Garrett\_Campen](https://avatars.discourse-cdn.com/v4/letter/g/ac91a4/32.png) [@Garrett\_Campen](https://discourse.codecombat.com/u/Garrett_Campen)\
**Post date:** [July 18, 2016, 5:56am UTC](https://discourse.codecombat.com/t/hunting-party-possible-bug-or-operator-error-python/8406/13 "2016-07-18T05:56:02Z")

</div>

took a couple day break thinking id come back to this being fixed now its a cannot read protected property error…what the deuce? lol

---

<div class="post-metadata">

**Author:** ![Neel\_Sharma](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@Neel\_Sharma](https://discourse.codecombat.com/u/Neel_Sharma)\
**Post date:** [July 18, 2016, 3:09pm UTC](https://discourse.codecombat.com/t/hunting-party-possible-bug-or-operator-error-python/8406/14 "2016-07-18T15:09:49Z")

</div>

I seriously have no idea what is with all these bugs but I’ve been getting that one too.

---

<div class="post-metadata">

**Author:** ![Anna](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/anna/32/8378_2.png) [@Anna](https://discourse.codecombat.com/u/Anna)\
**Post date:** [July 18, 2016, 5:48pm UTC](https://discourse.codecombat.com/t/hunting-party-possible-bug-or-operator-error-python/8406/15 "2016-07-18T17:48:16Z")

</div>

Me neither. I am still getting bugs.

---

<div class="post-metadata">

**Author:** ![Hunter\_Nixon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/hunter_nixon/32/11169_2.png) [@Hunter\_Nixon](https://discourse.codecombat.com/u/Hunter_Nixon)\
**Post date:** [December 19, 2019, 3:35pm UTC](https://discourse.codecombat.com/t/hunting-party-possible-bug-or-operator-error-python/8406/18 "2019-12-19T15:35:50Z")

</div>

I have the bug and this is three years later. I posted it on “Hunting Party - Please Help”
