Help codecombat hit and freeze

Do you remember this? :wink:

1 Like

not really:small_airplane:

In this case, go back to older levels to review what you have learned. Maybe the previous 5 - 10 levels. Then, apply those skills to this level.

2 Likes

i did that and i don,t now what to do:cry:

This can clarify a couple things for you :slightly_smiling_face:

1 Like

Let’s break it down a little bit for you:

# Call inAttackRange(enemy), with the enemy as the argument
# and save the result in the variable canAttack.

Call inAttackRange(enemy): You want to trigger the function that has been defined in the code at the top. You call this by typing in the function with an argument in the ( )'s. The argument it asks you is to place in the ( )'s is “enemy”.

Save as a variable: saving a variable is what the “=” is saved for.
Example: x = 5
In this example you’re saving ‘5’ to the variable ‘x’.

With this information we know the variable we want is ‘canAttack’, we use an ’ = ’ sign to define the variable. For the variable we want to call ‘inAttackRange()’ and for the argument in the ()'s place in ‘enemy’.

So the final result would be:

canAttack = inAttackRange(enemy)

After you have this you can then call and ‘if/else’ statement to make you’re character attack the enemy, you’ve done this already plenty times.

2 Likes

i did that :smile: hellenar

i understand but i want to show my code to you

// This function checks if the enemy is in your attack range.
function inAttackRange(enemy) {
var 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.
var enemy = hero.findNearestEnemy();

// Call inAttackRange(enemy), with the enemy as the argument
// and save the result in the variable canAttack.

var canAttack = inAttackRange(enemy);
// If the result stored in canAttack is true, then attack!
hero.attack(enemy);
}