Hit and Freeze Python


#1

I am stuck on the level, "Hit and Freeze."
This is my code:

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()
# Call inAttackRange(enemy), with the enemy as the argument
# and save the result in the variable canAttack.
canAttack = inAttackRange()
# If the result stored in canAttack is True, then attack!
hero.attack(enemy)
pass

PLEASE HELP:(:scream:


#2

NEVER MIND I PASSED IT :slight_smile:

ACTUALLY NOT :frowning:
NO I DID
SERIOUSLY


#3


#4

@agarionotpro

I’m confused. Did you pass the level or not?


#5

I finished the level


#6

which code did you use?

Mod edit: Please do not request solutions. The purpose of this board is to assist people with their code. Simply providing solutions is counter productive to the learning process. There are many people here willing and able to assist you with your code and help you figure out what the problem is, but we do not just give the answers. Thanks.


#7

Please do not ask for codes please


#8

I can’t find to finish the level


#9

Can you post your current code so we can help you?


#10

Wait, @SuperSmacker that’s a solution could you get rid of it. (actually it doesn’t really matter, do what you think)


#11

here is the code

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()
# Call inAttackRange(enemy), with the enemy as the argument
# and save the result in the variable canAttack.
canAttack = inAttackRange
# If the result stored in canAttack is True, then attack!
hero.attack(enemy)
pass

this code attacks the munchkins and kills 5 exactly but when the others escape the hero follows it and takes too much damage from the trap.


#12

Can you format your code so we can see clearly? Use the </> button to do that.


#13

Please learn to post 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 of your code inside the triple back tick marks.

``` <— Triple back tick marks.

Paste ALL of your code in here.

``` <— Triple back tick marks.

There are many people here willing and able to help. If you use the </> button correctly, then ALL of your code should look like this:

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
    else:
        hero.say("My code is formatted properly")

If ALL of your code isn’t formatted like the code above, then you’re doing it wrong and we can’t see the structure of the code to troubleshoot whether or not that is the issue. Use the </> button and help us help you. This works when sending a private message as well.

Thank you.


#14

But it takes us a long time to write these kind of posts, for just a tiny thing ;( LOL


#15

Nope. Copy and paste. I’ve posted that so many times that I have it saved.


#16

… (20 fainted @Chaboi_3000’s ) Maybe have a notepad of all copy and paste items. Then you can choose a variety of posts that are going to be repeated.


#17

Set up canned replies, it’s easier. Just click on the gear and set them up. :sunglasses:


#18

I’m sad that only admins and mods have them, we only have the default options ;(


#19

Oh, didn’t know that the option wasn’t available to you. Someday…

Until then, use a word doc or .txt. Still fast and easy.


#20

Btw moderation in discord servers are tough when so many people hate each other, I’m like warn then kick then ban, and it’s making me crazy. You’re lucky you’re a mod of a peaceful chat because mines are indescribably out of control.