# I neeed some help on hit and freeze i dont understand it

**URL:** <https://discourse.codecombat.com/t/i-neeed-some-help-on-hit-and-freeze-i-dont-understand-it/32478>\
**Category:** Level Help\
**Created:** [March 25, 2022, 11:04pm UTC](https://discourse.codecombat.com/t/i-neeed-some-help-on-hit-and-freeze-i-dont-understand-it/32478 "2022-03-25T23:04:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![calvin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/calvin/32/17585_2.png) [@calvin](https://discourse.codecombat.com/u/calvin)\
**Post date:** [March 25, 2022, 11:04pm UTC](https://discourse.codecombat.com/t/i-neeed-some-help-on-hit-and-freeze-i-dont-understand-it/32478/1 "2022-03-25T23:04:22Z")

</div>

my code is `# 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

# Attack ogres only when they’re within reach.

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

---

<div class="post-metadata">

**Author:** ![calvin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/calvin/32/17585_2.png) [@calvin](https://discourse.codecombat.com/u/calvin)\
**Post date:** [March 25, 2022, 11:24pm UTC](https://discourse.codecombat.com/t/i-neeed-some-help-on-hit-and-freeze-i-dont-understand-it/32478/2 "2022-03-25T23:24:03Z")

</div>

can someone help meee

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [March 26, 2022, 5:34am UTC](https://discourse.codecombat.com/t/i-neeed-some-help-on-hit-and-freeze-i-dont-understand-it/32478/3 "2022-03-26T05:34:55Z")

</div>

```python
# 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

# Attack ogres only when they’re within reach.

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

```

Please make sure your code is formatted, try for the next time to insert the code on a new line different from the text you out 🙂 I have formatted it for you for this time.

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [March 26, 2022, 5:40am UTC](https://discourse.codecombat.com/t/i-neeed-some-help-on-hit-and-freeze-i-dont-understand-it/32478/4 "2022-03-26T05:40:03Z")

</div>

> [@Aya](#):
>
> `meow = enemy`

so this is unnecessary, you can remove it.

> [@Aya](#):
>
> `# and save the result in the variable canAttack.`

This means that you should make a variable called `canAttack` and assign the function `inAttackRange(enemy)` to it.

Hint: `canAttack = inAttackRange(enemy)`

Now the `inAttackRange` function either returns `True` or `False` so this means that `canAttack`’s value will be True or False.

> [@Aya](#):
>
> `# If the result stored in canAttack is True, then attack!`

So make an if-statement chceking if `canAttack` is True, and if so, cleave.

---

<div class="post-metadata">

**Author:** ![calvin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/calvin/32/17585_2.png) [@calvin](https://discourse.codecombat.com/u/calvin)\
**Post date:** [March 29, 2022, 1:46am UTC](https://discourse.codecombat.com/t/i-neeed-some-help-on-hit-and-freeze-i-dont-understand-it/32478/5 "2022-03-29T01:46:34Z")

</div>

![Screenshot 2022-03-28 6.45.08 PM](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/2/f/2ff2add4ca1c3ccad008e2d63a5b05a98885f37a.jpeg)  
this is my code so far

---

<div class="post-metadata">

**Author:** ![calvin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/calvin/32/17585_2.png) [@calvin](https://discourse.codecombat.com/u/calvin)\
**Post date:** [March 29, 2022, 3:07am UTC](https://discourse.codecombat.com/t/i-neeed-some-help-on-hit-and-freeze-i-dont-understand-it/32478/6 "2022-03-29T03:07:38Z")

</div>

im kind of getting it so i need to attack without moving ^u^

---

<div class="post-metadata">

**Author:** ![calvin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/calvin/32/17585_2.png) [@calvin](https://discourse.codecombat.com/u/calvin)\
**Post date:** [March 29, 2022, 3:15am UTC](https://discourse.codecombat.com/t/i-neeed-some-help-on-hit-and-freeze-i-dont-understand-it/32478/7 "2022-03-29T03:15:15Z")

</div>

i didnt cleave

- List item

---

<div class="post-metadata">

**Author:** ![calvin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/calvin/32/17585_2.png) [@calvin](https://discourse.codecombat.com/u/calvin)\
**Post date:** [March 29, 2022, 3:16am UTC](https://discourse.codecombat.com/t/i-neeed-some-help-on-hit-and-freeze-i-dont-understand-it/32478/8 "2022-03-29T03:16:44Z")

</div>

I FORGOT ABOUT THE ATTACK ENEMY ON TOP OF THE if canAttack:

---

<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:** [March 29, 2022, 3:17pm UTC](https://discourse.codecombat.com/t/i-neeed-some-help-on-hit-and-freeze-i-dont-understand-it/32478/9 "2022-03-29T15:17:09Z")

</div>

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