# Stuck on level Hit and Freeze

**URL:** <https://discourse.codecombat.com/t/stuck-on-level-hit-and-freeze/24607>\
**Category:** Level Help\
**Created:** [October 3, 2020, 8:36pm UTC](https://discourse.codecombat.com/t/stuck-on-level-hit-and-freeze/24607 "2020-10-03T20:36:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Joseph](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/michael_joseph/32/15175_2.png) [@Michael\_Joseph](https://discourse.codecombat.com/u/Michael_Joseph)\
**Post date:** [October 3, 2020, 8:36pm UTC](https://discourse.codecombat.com/t/stuck-on-level-hit-and-freeze/24607/1 "2020-10-03T20:36:21Z")

</div>

What do I do? How do I make my hero attack the enemies without killing himself by moving towards them?

# You are trapped. Don’t move, it’ll be painful.

# This function checks if the enemy is in your attack range.

def inAttackRange(enemy):  
distance = hero.distanceTo(enemy)  
# Almost all swords have attack range of 3.  
if distance \<= 3:  
return True  
else:  
return False  
pass

# Attack ogres only when they’re within reach.

while True:  
# Find the nearest enemy and store it in a variable.  
enemy = hero.findNearestEnemy()  
# Call inAttackRange(enemy), with the enemy as the argument  
inAttackRange(enemy)  
# and save the result in the variable canAttack.  
canAttack = inAttackRange(enemy)  
# If the result stored in canAttack is True, then attack!  
if inAttackRange is True:  
hero.attack(enemy)  
pass

---

<div class="post-metadata">

**Author:** ![AnSeDra](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ansedra/32/13123_2.png) [@AnSeDra](https://discourse.codecombat.com/u/AnSeDra)\
**Post date:** [October 3, 2020, 8:40pm UTC](https://discourse.codecombat.com/t/stuck-on-level-hit-and-freeze/24607/2 "2020-10-03T20:40:12Z")

</div>

Hello and welcome to codecombat discourse @Michael_Joseph! 🥳 This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review [this topic](https://discourse.codecombat.com/t/welcome-to-codecombat-discourse-forums/15601), which shows all essentials of this board! Thanks!

Can you please format your code as it is described below so we will be able to help you solve the level?

> [@\[Essentials\] How To Post/Format Your Code Correctly](https://discourse.codecombat.com/t/essentials-how-to-post-format-your-code-correctly/15521):
>
> Formatting your code before posting code is essential to our community, and if you don’t we might not be able to help frowning Everyone must know how to format ALL of your code properly. It’s really easy and only requires a very small amount of effort. To post your code from the game , use the \</\> button or it won’t format properly. When you click the \</\> button, the following will appear: Please paste ALL …

Andrei

---

<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 3, 2020, 8:52pm UTC](https://discourse.codecombat.com/t/stuck-on-level-hit-and-freeze/24607/3 "2020-10-03T20:52:00Z")

</div>

@Michael_Joseph As I told you before, please do not post about the same topic in different topics, it causes clutter in the Discourse.  
Lydia
