# How to pass Blind Distance

**URL:** <https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290>\
**Category:** Level Help\
**Created:** [December 16, 2017, 7:26pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290 "2017-12-16T19:26:53Z")\
**Posts on this page:** 16\
**Page:** 2

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [May 26, 2021, 7:36am UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/21 "2021-05-26T07:36:38Z")

</div>

That code gets success in my level. Please could you post a screenshot of the level screen, and of your equipment. And also, could you post your code with indents: the gaps at the start of each line.  
Put ``` on two new lines in the text editor of the forum, then post in your code directly from codecombat and it will have the spaces.  
Danny

---

<div class="post-metadata">

**Author:** ![Ashton\_Gifford](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ashton_gifford/32/24614_2.png) [@Ashton\_Gifford](https://discourse.codecombat.com/u/Ashton_Gifford)\
**Post date:** [May 26, 2021, 10:29am UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/22 "2021-05-26T10:29:48Z")

</div>

here’s my gear:  
 ![Screenshot 2021-05-26 6.23.43 AM](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/b/3/b3801e0a38561ec1fe71cfdc5909f97fd4560d66.png)  
hear’s my code:

```python
def nearestEnemyDistance():
   enemy = hero.findNearestEnemy()
result = 0
if enemy:
    result = hero.distanceTo(enemy)
return result

while True:
    # Call nearestEnemyDistance() and
# save the result in the variable enemyDistance.
   enemydistance = nearestEnemyDistance()

# If the enemyDistance is greater than 0:
if enemydistance > 0:
    
    # Say the value of enemyDistance variable.
    hero.say(enemydistance)

```

![Screenshot 2021-05-26 6.32.19 AM](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/c/9/c9e93d13ddd1edd6b9c096f98a61acd661f127e4.png)  
It still keeps saying this though.

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [May 26, 2021, 10:32am UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/23 "2021-05-26T10:32:12Z")

</div>

Your indentation is still off. See how the lines aren’t in the right place on your post? Please put spaces at the start of the lines so I can see exactly how much indentation you have at the beginning of each line. You could also just post a screenshot of the actual level screen with the code and the map of the level.

---

<div class="post-metadata">

**Author:** ![Ashton\_Gifford](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ashton_gifford/32/24614_2.png) [@Ashton\_Gifford](https://discourse.codecombat.com/u/Ashton_Gifford)\
**Post date:** [May 26, 2021, 10:38am UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/24 "2021-05-26T10:38:21Z")

</div>

![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/3/2/32a94ebe99bcdf02b76f6081bf8bd9714cdc873c.jpeg)

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [May 26, 2021, 2:20pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/25 "2021-05-26T14:20:25Z")

</div>

Ah, I see. Indentation is the problem. If you have a function (starts with def) or a loop (like while True) all the rest of the code should be “inside” it. You got that right for the first line:

```python
def nearestEnemyDistance():
   enemy = hero.findNearestEnemy()

```

But the rest of it is too far to the left. It needs to go 4 spaces to the right—\>

```python
result = 0
if enemy:
    result = hero.distanceTo(enemy)
return result

```

Same for the next bit. The first line is right:

```python
while True:
    # Call nearestEnemyDistance() and
# save the result in the variable enemyDistance.
   enemydistance = nearestEnemyDistance()

```

But the rest needs to go 4 spaces right:

> [@Ashton\_Gifford](#):
>
> ```python
> # If the enemyDistance is greater than 0:
> if enemydistance > 0:
>     
> # Say the value of enemyDistance variable.
> hero.say(enemydistance)
> 
> ```

---

<div class="post-metadata">

**Author:** ![Ashton\_Gifford](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ashton_gifford/32/24614_2.png) [@Ashton\_Gifford](https://discourse.codecombat.com/u/Ashton_Gifford)\
**Post date:** [May 27, 2021, 3:05pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/26 "2021-05-27T15:05:48Z")

</div>

ok thanks. I’ll try it

---

<div class="post-metadata">

**Author:** ![QED](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/qed/32/20159_2.png) [@QED](https://discourse.codecombat.com/u/QED)\
**Post date:** [May 28, 2021, 5:06pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/27 "2021-05-28T17:06:46Z")

</div>

This is my code and not working (see after return result) and when hero call distance (and say this)?

I need help and thank you.

Screen shot (Python code) in level map in English:

![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/f/5/f54503964c9214505611de4b9a1569a271650ae6.png)

---

<div class="post-metadata">

**Author:** ![QED](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/qed/32/20159_2.png) [@QED](https://discourse.codecombat.com/u/QED)\
**Post date:** [May 28, 2021, 5:38pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/28 "2021-05-28T17:38:44Z")

</div>

Mayde line 13 is if enemy: distance = …  
line 14: say distance . I think is ok code? (only distance not " " this marks).

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [May 28, 2021, 5:42pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/29 "2021-05-28T17:42:46Z")

</div>

The only problem in your code @QED is this line:

```python
if enemy.distance > 0:

```

enemy.distance is not a thing. enemyDistance, the variable you have just defined is a thing and is different from enemy.distance which won’t return any result.  
So switch that to enemyDistance, because you need to use the variable you created in your function nearestEnemyDistance().  
Danny

---

<div class="post-metadata">

**Author:** ![QED](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/qed/32/20159_2.png) [@QED](https://discourse.codecombat.com/u/QED)\
**Post date:** [May 30, 2021, 1:21pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/30 "2021-05-30T13:21:47Z")

</div>

If no comments in code.

Thank you, I’m just testing in my code (in add while-true loop in after the line 12):  
lines 13, 14, 15

But is not work yet.

This is this code:

and enemy Distance()

I just add this code after def (loop, after return result in while true loop:

![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/9/3/934f65791993a1cf0f953b2b59094a8da2641434.png)

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [May 31, 2021, 5:58pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/31 "2021-05-31T17:58:23Z")

</div>

I’m afraid that’s not quite right either.  
You still need to check if enemyDistance \> 0 and hero.say(enemyDistance). You don’t want to do:  
if enemy:  
You want:  
if enemyDistance \> 0:  
Then you need to say enemyDistance, the variable itself, Not hero.distanceTo(enemy).  
Danny

---

<div class="post-metadata">

**Author:** ![Ashton\_Gifford](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ashton_gifford/32/24614_2.png) [@Ashton\_Gifford](https://discourse.codecombat.com/u/Ashton_Gifford)\
**Post date:** [June 1, 2021, 12:53pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/32 "2021-06-01T12:53:51Z")

</div>

![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/a/3/a3f8329c06f35402150f40de3d423fe7228b96f9.png)  
what am i doing wrong?  
its not saying this anymore thankfully  
 ![Screenshot 2021-05-26 6.32.19 AM](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/c/9/c9e93d13ddd1edd6b9c096f98a61acd661f127e4.png)  
but its still not… working

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [June 1, 2021, 3:22pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/33 "2021-06-01T15:22:10Z")

</div>

You’ve got the code itself exactly right. The only problem is the indentation. All of the lines in the nearestEnemyDistance() function need to be four spaces forwards, the same goes for the while True loop. So

```python
enemy = hero.findNearestEnemy()
if enemy:
    result = hero.distanceTo(enemy)

```

and:

```python
if enemyDistance > 0:
    hero.say(enemyDistance)

```

Both need to go forwards 4 spaces. Then it should work

---

<div class="post-metadata">

**Author:** ![Ashton\_Gifford](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ashton_gifford/32/24614_2.png) [@Ashton\_Gifford](https://discourse.codecombat.com/u/Ashton_Gifford)\
**Post date:** [June 1, 2021, 3:24pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/34 "2021-06-01T15:24:29Z")

</div>

![Screenshot 2021-06-01 11.23.54 AM](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/2/e/2eea417a17ff3bc784fda0f759ec1b1d3aaee327.jpeg)  
still not working  
its stuck trying to run `nearestEnemyDistance()`

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [June 1, 2021, 6:04pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/35 "2021-06-01T18:04:44Z")

</div>

You haven’t moved these lines four spaces forwards like I said:

> [@Deadpool198](#):
>
> ```python
> enemy = hero.findNearestEnemy()
> if enemy:
> result = hero.distanceTo(enemy)
> 
> ```

That’s in the nearestEnemy function.

---

<div class="post-metadata">

**Author:** ![Ashton\_Gifford](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ashton_gifford/32/24614_2.png) [@Ashton\_Gifford](https://discourse.codecombat.com/u/Ashton_Gifford)\
**Post date:** [June 3, 2021, 12:55pm UTC](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290/36 "2021-06-03T12:55:27Z")

</div>

thank you. its working now.

[Previous page](https://discourse.codecombat.com/t/how-to-pass-blind-distance/13290.md?page=1)
