# Having trouble with Agrippa defense

**URL:** <https://discourse.codecombat.com/t/having-trouble-with-agrippa-defense/2506>\
**Category:** Level Help\
**Created:** [January 29, 2015, 10:25pm UTC](https://discourse.codecombat.com/t/having-trouble-with-agrippa-defense/2506 "2015-01-29T22:25:05Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![VladTheImpaler](https://avatars.discourse-cdn.com/v4/letter/v/bc8723/32.png) [@VladTheImpaler](https://discourse.codecombat.com/u/VladTheImpaler)\
**Post date:** [January 29, 2015, 10:25pm UTC](https://discourse.codecombat.com/t/having-trouble-with-agrippa-defense/2506/1 "2015-01-29T22:25:05Z")

</div>

```python
loop:
    enemy = self.distanceTo()
    if enemy < 5:
        self.cleave(enemy) 
    else:
        self.attack(enemy)

```

---

<div class="post-metadata">

**Author:** ![sotonin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sotonin/32/24089_2.png) [@sotonin](https://discourse.codecombat.com/u/sotonin)\
**Post date:** [January 29, 2015, 10:27pm UTC](https://discourse.codecombat.com/t/having-trouble-with-agrippa-defense/2506/2 "2015-01-29T22:27:53Z")

</div>

You are kind of mixed up there.

enemy should be set to findNearestEnemy not distanceTo

```python
enemy = self.findNearestEnemy()

```

then you need to store distance

```python
distance = self.distanceTo(enemy)

```

then

```python
if distance < 5:

```

but dont forget to check if enemy exists before getting the distance

---

<div class="post-metadata">

**Author:** ![VladTheImpaler](https://avatars.discourse-cdn.com/v4/letter/v/bc8723/32.png) [@VladTheImpaler](https://discourse.codecombat.com/u/VladTheImpaler)\
**Post date:** [January 29, 2015, 10:38pm UTC](https://discourse.codecombat.com/t/having-trouble-with-agrippa-defense/2506/3 "2015-01-29T22:38:16Z")

</div>

i get unexpected token when i try and store distance

`distance = self.distanceTo(enemy)`

---

<div class="post-metadata">

**Author:** ![VladTheImpaler](https://avatars.discourse-cdn.com/v4/letter/v/bc8723/32.png) [@VladTheImpaler](https://discourse.codecombat.com/u/VladTheImpaler)\
**Post date:** [January 29, 2015, 10:40pm UTC](https://discourse.codecombat.com/t/having-trouble-with-agrippa-defense/2506/4 "2015-01-29T22:40:23Z")

</div>

```python
loop:
    enemy = self.findNearestEnemy()
    distance = self.distanceTo(enemy)
    if enemy:
        pass
    if distance < 5:
        self.cleave(enemy)
    else:
        self.attack(enemy)

```

---

<div class="post-metadata">

**Author:** ![Rytrik](https://avatars.discourse-cdn.com/v4/letter/r/3e96dc/32.png) [@Rytrik](https://discourse.codecombat.com/u/Rytrik)\
**Post date:** [January 29, 2015, 10:49pm UTC](https://discourse.codecombat.com/t/having-trouble-with-agrippa-defense/2506/5 "2015-01-29T22:49:00Z")

</div>

Try having `distance = self.distanceTo(enemy)` after `if enemy:` . Right now it doesn’t know if there’s an enemy or not to find a distance to, so how can it find a distance to a possible enemy that’s possibly not there? 🙂

---

<div class="post-metadata">

**Author:** ![VladTheImpaler](https://avatars.discourse-cdn.com/v4/letter/v/bc8723/32.png) [@VladTheImpaler](https://discourse.codecombat.com/u/VladTheImpaler)\
**Post date:** [January 29, 2015, 10:54pm UTC](https://discourse.codecombat.com/t/having-trouble-with-agrippa-defense/2506/6 "2015-01-29T22:54:48Z")

</div>

Im still confused, i moved it under if enemy and still didnt fix the problem…

---

<div class="post-metadata">

**Author:** ![VladTheImpaler](https://avatars.discourse-cdn.com/v4/letter/v/bc8723/32.png) [@VladTheImpaler](https://discourse.codecombat.com/u/VladTheImpaler)\
**Post date:** [January 29, 2015, 11:04pm UTC](https://discourse.codecombat.com/t/having-trouble-with-agrippa-defense/2506/7 "2015-01-29T23:04:41Z")

</div>

```python
loop:
    enemy = self.findNearestEnemy()
     distance = self.distanceTo(enemy)
    if enemy:
        pass
    if distance < 5:
        self.cleave(enemy)
    else:
        self.attack(enemy)

```

---

<div class="post-metadata">

**Author:** ![VladTheImpaler](https://avatars.discourse-cdn.com/v4/letter/v/bc8723/32.png) [@VladTheImpaler](https://discourse.codecombat.com/u/VladTheImpaler)\
**Post date:** [January 29, 2015, 11:36pm UTC](https://discourse.codecombat.com/t/having-trouble-with-agrippa-defense/2506/8 "2015-01-29T23:36:02Z")

</div>

The levels before this one were pretty easy,but i hit a brick wall here…why no real help…i used what has been givin so far and has not helped…i want to keep learning but not sure what else to do

---

<div class="post-metadata">

**Author:** ![sotonin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sotonin/32/24089_2.png) [@sotonin](https://discourse.codecombat.com/u/sotonin)\
**Post date:** [January 29, 2015, 11:36pm UTC](https://discourse.codecombat.com/t/having-trouble-with-agrippa-defense/2506/9 "2015-01-29T23:36:34Z")

</div>

You can not call any function that passes in enemy without having it inside an if enemy block. thats your problem.

---

<div class="post-metadata">

**Author:** ![VladTheImpaler](https://avatars.discourse-cdn.com/v4/letter/v/bc8723/32.png) [@VladTheImpaler](https://discourse.codecombat.com/u/VladTheImpaler)\
**Post date:** [January 29, 2015, 11:43pm UTC](https://discourse.codecombat.com/t/having-trouble-with-agrippa-defense/2506/10 "2015-01-29T23:43:11Z")

</div>

like this? my dude just stands there

```python
loop:
    enemy = self.findNearestEnemy()
    if enemy:
        pass
        distance = self.distanceTo()
    if distance < 5:
        self.attack(enemy)
    else:
        self.cleave(enemy)

```

---

<div class="post-metadata">

**Author:** ![dwhittaker](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dwhittaker/32/2114_2.png) [@dwhittaker](https://discourse.codecombat.com/u/dwhittaker)\
**Post date:** [January 30, 2015, 12:07am UTC](https://discourse.codecombat.com/t/having-trouble-with-agrippa-defense/2506/11 "2015-01-30T00:07:42Z")

</div>

The problem is your line `pass`

If you enter your code using the code tag it makes it easier for us to see your indentation. I’ve updated your code with the tag to help see what is happening. (If you edit the post you can see how I did it.)

You need to indent the line  
`if distance < 5:`  
and the others after it. You are only checking distance if there is an enemy.

Currently your code says if there is an enemy calculate the distance. Regardless of the previous answer, if the distance is under 5 attack the enemy, otherwise cleave.

To put it in another context, it is like you have written out interview questions:

First, ask if there are cookies.  
Then ask if the cookies are chocolate chip.  
If they are not chocolate chip, then they must be oatmeal raisin.

imagine you have this conversation with your mom:

You: Do we have any cookies?  
Mom: No  
You: Are they chocolate chip cookies?  
Mom: ???

If the first answer is no, you shouldn’t do anything. If the first answer is yes, then you will want to check the cookie type.

Hope that made sense.

---

<div class="post-metadata">

**Author:** ![VladTheImpaler](https://avatars.discourse-cdn.com/v4/letter/v/bc8723/32.png) [@VladTheImpaler](https://discourse.codecombat.com/u/VladTheImpaler)\
**Post date:** [January 30, 2015, 12:13am UTC](https://discourse.codecombat.com/t/having-trouble-with-agrippa-defense/2506/12 "2015-01-30T00:13:35Z")

</div>

hmm yeah maybe i need to go watch more tutorials on youtube…thanks for trying to help me tho

---

<div class="post-metadata">

**Author:** ![sotonin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sotonin/32/24089_2.png) [@sotonin](https://discourse.codecombat.com/u/sotonin)\
**Post date:** [January 30, 2015, 12:15am UTC](https://discourse.codecombat.com/t/having-trouble-with-agrippa-defense/2506/13 "2015-01-30T00:15:13Z")

</div>

> [@VladTheImpaler](#):
>
> loop:  
> enemy = self.findNearestEnemy()  
> if enemy:  
> pass  
> distance = self.distanceTo()  
> if distance \< 5:  
> self.attack(enemy)  
> else:  
> self.cleave(enemy)

```python
loop:
    enemy = self.findNearestEnemy()
    if enemy:
        distance = self.distanceTo(enemy)
        if distance < 5:
            self.cleave(enemy)
        else:
            self.attack(enemy)

```

---

<div class="post-metadata">

**Author:** ![RainbowUnicornPanda](https://avatars.discourse-cdn.com/v4/letter/r/eb9ed0/32.png) [@RainbowUnicornPanda](https://discourse.codecombat.com/u/RainbowUnicornPanda)\
**Post date:** [January 31, 2015, 7:35am UTC](https://discourse.codecombat.com/t/having-trouble-with-agrippa-defense/2506/14 "2015-01-31T07:35:10Z")

</div>

Any help??? I cleave just fine, but Anya just stands there while munchkin ogres spill her blood all over the meadow. I am using Java Script.

```python
loop {
    var enemy = this.findNearestEnemy();
    if(enemy) {
        var distance = this.distanceTo(enemy);
        if (distance < 5)
        if (this.isReady("cleave"))
        this.cleave();
    }
    else {
        this.attack(enemy);
    }
}

```

---

<div class="post-metadata">

**Author:** ![Feinty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/feinty/32/1869_2.png) [@Feinty](https://discourse.codecombat.com/u/Feinty)\
**Post date:** [February 1, 2015, 4:43am UTC](https://discourse.codecombat.com/t/having-trouble-with-agrippa-defense/2506/15 "2015-02-01T04:43:00Z")

</div>

you are forgetting a { after your distance check

---

<div class="post-metadata">

**Author:** ![Portgas\_D\_Ace](https://avatars.discourse-cdn.com/v4/letter/p/59ef9b/32.png) [@Portgas\_D\_Ace](https://discourse.codecombat.com/u/Portgas_D_Ace)\
**Post date:** [February 1, 2015, 4:55am UTC](https://discourse.codecombat.com/t/having-trouble-with-agrippa-defense/2506/16 "2015-02-01T04:55:40Z")

</div>

you forgot to use { } in your **if** commands  
well in this round you’ll need extreme amount of health i think? ( i have Tharin with 491HP and ended up to 61HP) so instead of attacking in my **else** i just shielded til my cleave is ready to use.or maybe you can just run around? i don’t know. but hey i survived the round 😄

---

<div class="post-metadata">

**Author:** ![Rommie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/rommie/32/27588_2.png) [@Rommie](https://discourse.codecombat.com/u/Rommie)\
**Post date:** [February 2, 2015, 7:06am UTC](https://discourse.codecombat.com/t/having-trouble-with-agrippa-defense/2506/17 "2015-02-02T07:06:20Z")

</div>

```
loop:
enemy = self.findNearestEnemy()
if enemy:
    distance = self.distanceTo(enemy)    
    if distance < 5:
        self.cleave(enemy)
    else:
        self.attack(enemy)

```

She attacks the first group fine, but the next group kills her. ☹

Help please

---

<div class="post-metadata">

**Author:** ![J\_F\_B\_M](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/j_f_b_m/32/2756_2.png) [@J\_F\_B\_M](https://discourse.codecombat.com/u/J_F_B_M)\
**Post date:** [February 2, 2015, 9:48am UTC](https://discourse.codecombat.com/t/having-trouble-with-agrippa-defense/2506/18 "2015-02-02T09:48:09Z")

</div>

**Indentations, they will save your life!**

You want your code too look like this:

```python
loop:
    # <- Note the four spaces
    enemy = self.findNearestEnemy()
    if enemy:
        #kill him just like above (again with 4 more spaces, 8 total)

```

With indentation you tell python what is inside and what is outside of a loop/if/…

---

<div class="post-metadata">

**Author:** ![Rommie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/rommie/32/27588_2.png) [@Rommie](https://discourse.codecombat.com/u/Rommie)\
**Post date:** [February 2, 2015, 6:46pm UTC](https://discourse.codecombat.com/t/having-trouble-with-agrippa-defense/2506/19 "2015-02-02T18:46:25Z")

</div>

Hi J\_F,

Thank you. When copying and pasting the 1st two lines it removed the indent (4 spaces)

Here is the screenshot. While she’s been hacked to death it stays highlighted on line 6.

![](https://sea2.discourse-cdn.com/flex016/uploads/codecombat/2008/9f8dcd4b1fa77213.png)

Below is the error i get if I try to indent line 3.  
 ![](https://sea2.discourse-cdn.com/flex016/uploads/codecombat/2009/a77f68eaecdf1c15.png)

---

<div class="post-metadata">

**Author:** ![Rommie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/rommie/32/27588_2.png) [@Rommie](https://discourse.codecombat.com/u/Rommie)\
**Post date:** [February 2, 2015, 6:56pm UTC](https://discourse.codecombat.com/t/having-trouble-with-agrippa-defense/2506/20 "2015-02-02T18:56:27Z")

</div>

I found out what it was. Her armor wasn’t strong enough to handle the battle. I purchased new armor and she was fine.

I tried to shield her initially, but that didn’t work. Thanks for the help!!

[Next page](https://discourse.codecombat.com/t/having-trouble-with-agrippa-defense/2506.md?page=2)
