# \[SOLVED\]Ok for real I am really confused with the level Mind The Trap

**URL:** <https://discourse.codecombat.com/t/solved-ok-for-real-i-am-really-confused-with-the-level-mind-the-trap/25085>\
**Category:** Level Help\
**Created:** [October 29, 2020, 5:43pm UTC](https://discourse.codecombat.com/t/solved-ok-for-real-i-am-really-confused-with-the-level-mind-the-trap/25085 "2020-10-29T17:43:59Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![LunAero\_Gaming](https://avatars.discourse-cdn.com/v4/letter/l/e79b87/32.png) [@LunAero\_Gaming](https://discourse.codecombat.com/u/LunAero_Gaming)\
**Post date:** [October 29, 2020, 5:43pm UTC](https://discourse.codecombat.com/t/solved-ok-for-real-i-am-really-confused-with-the-level-mind-the-trap/25085/1 "2020-10-29T17:43:59Z")

</div>

Ok so I am confused, whenever I try to make the `if (dist > 10):` command work and it isn’t working, when I do the correction it wants me to it fails with the Ran Out of Time failure text; if anyone wants to see my code here it is:

```python
# If you try to attack a distant enemy, your hero will charge toward it, ignoring all flags.
# You'll need to make sure you only attack enemies who are close to you!

while True:
    flag = hero.findFlag()
    enemy = hero.findNearestEnemy()
    
    if flag:
        # Pick up the flag.
        hero.pickUpFlag(flag)
        hero.say("I should pick up the flag.")
    elif enemy:
        # Only attack if the enemy distance is < 10 meters
        if (dist < 10):
            hero.attack(enemy)

```

and I can attach a screenshot if anyone needs me to as well I can attatch it later on…

---

<div class="post-metadata">

**Author:** ![PeterPalov](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/peterpalov/32/45280_2.png) [@PeterPalov](https://discourse.codecombat.com/u/PeterPalov)\
**Post date:** [October 29, 2020, 6:09pm UTC](https://discourse.codecombat.com/t/solved-ok-for-real-i-am-really-confused-with-the-level-mind-the-trap/25085/2 "2020-10-29T18:09:11Z")

</div>

Hello, @LunAero_Gaming and welcome to the Forum! 🥳

> [@LunAero\_Gaming](#):
>
> ` if (dist < 10):`

Maybe:  
`if hero.distanceTo(enemy) <10:`?

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [October 29, 2020, 6:11pm UTC](https://discourse.codecombat.com/t/solved-ok-for-real-i-am-really-confused-with-the-level-mind-the-trap/25085/3 "2020-10-29T18:11:21Z")

</div>

@LunAero_Gaming you have to be specific with your code you shouldn’t use words that aren’t a tactic

---

<div class="post-metadata">

**Author:** ![Lydia\_Song](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lydia_song/32/31461_2.png) [@Lydia\_Song](https://discourse.codecombat.com/u/Lydia_Song)\
**Post date:** [October 29, 2020, 10:00pm UTC](https://discourse.codecombat.com/t/solved-ok-for-real-i-am-really-confused-with-the-level-mind-the-trap/25085/4 "2020-10-29T22:00:27Z")

</div>

> [@LunAero\_Gaming](#):
>
> `if (dist < 10):`

Have you defined dist yet? You have to define dist first in order for your code to work.  
So you would do `hero.distanceTo(enemy)` in the very beginning of your while-True loop.  
Or you could do it the way PeterPalov did it.  
Lydia

---

<div class="post-metadata">

**Author:** ![PeterPalov](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/peterpalov/32/45280_2.png) [@PeterPalov](https://discourse.codecombat.com/u/PeterPalov)\
**Post date:** [October 30, 2020, 4:55am UTC](https://discourse.codecombat.com/t/solved-ok-for-real-i-am-really-confused-with-the-level-mind-the-trap/25085/5 "2020-10-30T04:55:18Z")

</div>

Yeah, or you can do:

```python
dist = hero.distanceTo(enemy)
if dist < 10:

```

---

<div class="post-metadata">

**Author:** ![LunAero\_Gaming](https://avatars.discourse-cdn.com/v4/letter/l/e79b87/32.png) [@LunAero\_Gaming](https://discourse.codecombat.com/u/LunAero_Gaming)\
**Post date:** [November 2, 2020, 5:54pm UTC](https://discourse.codecombat.com/t/solved-ok-for-real-i-am-really-confused-with-the-level-mind-the-trap/25085/6 "2020-11-02T17:54:36Z")

</div>

ok so I am trying these right now I have yet to try it but here is my current code: (also sorry for late reply)

```python
# If you try to attack a distant enemy, your hero will charge toward it, ignoring all flags.
# You'll need to make sure you only attack enemies who are close to you!

while True:
    flag = hero.findFlag()
    enemy = hero.findNearestEnemy()
    
    if flag:
        # Pick up the flag.
        hero.pickUpFlag(flag)
        hero.say("I should pick up the flag.")
    elif enemy:
        # Only attack if the enemy distance is < 10 meters
        dist = hero.distanceTo(enemy)
        if dist < 10

```

I will try these after another reply since I am really busy lately  
also edit: just noticed there is an error

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/a/2/a2a47851c07a14ae9c538459cab7b1cbff99aa92.jpeg)  
not sure how to fix it

---

<div class="post-metadata">

**Author:** ![abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@abc](https://discourse.codecombat.com/u/abc)\
**Post date:** [November 2, 2020, 6:05pm UTC](https://discourse.codecombat.com/t/solved-ok-for-real-i-am-really-confused-with-the-level-mind-the-trap/25085/7 "2020-11-02T18:05:57Z")

</div>

You need to add a colon at the end of an if statement, so  
`if dist < 10`  
would be  
`if dist < 10:`

---

<div class="post-metadata">

**Author:** ![Lydia\_Song](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lydia_song/32/31461_2.png) [@Lydia\_Song](https://discourse.codecombat.com/u/Lydia_Song)\
**Post date:** [November 2, 2020, 6:07pm UTC](https://discourse.codecombat.com/t/solved-ok-for-real-i-am-really-confused-with-the-level-mind-the-trap/25085/8 "2020-11-02T18:07:07Z")

</div>

> [@LunAero\_Gaming](#):
>
> `if dist < 10`

Add a colon at the end  
You also need to add an attack inside this if statement.  
Lydia

---

<div class="post-metadata">

**Author:** ![LunAero\_Gaming](https://avatars.discourse-cdn.com/v4/letter/l/e79b87/32.png) [@LunAero\_Gaming](https://discourse.codecombat.com/u/LunAero_Gaming)\
**Post date:** [November 2, 2020, 6:20pm UTC](https://discourse.codecombat.com/t/solved-ok-for-real-i-am-really-confused-with-the-level-mind-the-trap/25085/9 "2020-11-02T18:20:08Z")

</div>

thx will try now, this is been pretty challenging

---

<div class="post-metadata">

**Author:** ![Lydia\_Song](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lydia_song/32/31461_2.png) [@Lydia\_Song](https://discourse.codecombat.com/u/Lydia_Song)\
**Post date:** [November 2, 2020, 7:00pm UTC](https://discourse.codecombat.com/t/solved-ok-for-real-i-am-really-confused-with-the-level-mind-the-trap/25085/11 "2020-11-02T19:00:31Z")

</div>

Please remove the working code as it is against the Discourse rules.  
And congrats on solving the level!  
Lydia

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/a/a9445509d1a758c41b5ddcddc8c8e20a5dedb67f.png) [@system](https://discourse.codecombat.com/u/system)\
**Post date:** [November 3, 2020, 7:00am UTC](https://discourse.codecombat.com/t/solved-ok-for-real-i-am-really-confused-with-the-level-mind-the-trap/25085/12 "2020-11-03T07:00:43Z")

</div>

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
