Village Rover:help if you can

The Code:
while True:
# Now you can patrol the village using findAndAttackEnemy
hero.moveXY(35, 34)

# Now move to the right entrance.
hero.moveXY(60, 31)
# Use findAndAttackEnemy

The hero moves to the left, hits the enemy and removes half of its health, moves to the right, doesn’t even hit the enemy, then moves a little to the left before it ends.

What happened to the second half of the code i had written?

Formatting guide

Note the difference between using a function as a value, findAndAttackEnemy, and actually calling the function, findAndAttackEnemy(). The latter actually executes the code defined above in the function block.

Note the parenthesis.

You say your hero only removes half the health of the left enemy? Try modifying findAndAttackEnemy to attack twice (or more, if necessary).

1 Like

Hi! I’m not sure if what you need to do is the same as finding and attacking an enemy, but I will give you the example anyway, for this you need to create a variable called enemy and that it has the value of finding the closest enemy, then use attack al enemy with this variable inside the parameter of that method.

//Javascript example:
var enemy = hero.findNearestEnemy();

    hero.attack(enemy); //Is this what you need to do?

With this code what you do is say “if, there is an enemy nearby then attack”.

1 Like

You may not be aware, but the level in question provides the necessary findAndAttackEnemy function.

1 Like

I’ll use hydrobolic,s help and that dose not work I’ll try your code and see if it works okay.

Thanks a lot! I was trying to figure it out for 20 minuets while bashing my head in mentally.


How did you find the solution, what did you do? :smiley:

1 Like

I had added 1 or 2 #findandattackenemy lines and it worked. It was 10:00 pm so i get why I couldn’t solve it. :sweat_smile:

1 Like

Wow congratz!
In the same way, maybe instead of using the same one twice, maybe it is better to use a while (enemy) {findEneemyAndAttack} or something similar to loop until the enemy is killed

1 Like

yeah but it works similarly so why not.

Exactly! :smiley: but in the future if you need to make something repeat a while it will help you a lot (like a recommendation). it is very useful.

Example in javascript:

While (condition) {
     // some of code
1 Like

yeah but it’ll work for now.

1 Like

how do i use the target function? #off-topic

what do you need to do exactly? share me a screenshot or something

def hitOrHide(target):
    # If 'target' exists:
        # Attack 'target'.
        # Then move to the red mark.

I don’t know what it means by

`# If 'target' exists:
        # Attack 'target'.`

#Level Help I learned how to format code. #off-topic when I was typing I sneezed and hit my head.XD

English and simple code are pretty one-to-one

# If 'target' exists:
    # Attack 'target'.
if target:

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