# This defines a function called findAndAttackEnemy def findAndAttackEnemy(): enemy = hero.findNearestEnemy() if enemy: hero.attack(enemy) # This code is not part of the function. while True: # Now you can patrol the village using findAndAttackEnemy hero.moveXY(35, 34) findAndAttackEnemy() # Now move to the right entrance. hero.moveXY(59,31) # Use findAndAttackEnemy enemy = hero.findNearestEnemy() hero.attack(enemy)
Zax, please also remember to include what the problem is…it might not always be obvious.
Lines 16 & 17 (the last two) are not doing what the instructions in the comment on line 15 says…
@dedreous my problem is that is cant get rid of the last ogre so i lose after that
Take a look at lines 9 - 11. The comment on 9 is saying “now, patrol the village and use the function (definition) findAndAttackEnemy”
So, on line 10, the you move the hero to the first patrol point (X) and then call the function.
Line 14 is saying “call the function again”…you can delete everything from line 15 down, replacing it with the function call.
okay i will try that
# Use the checkAndAttack function to make your code easy to read. # This function has a parameter. # An parameter is a way of passing information into a function. def checkAndAttack(target): # The 'target' parameter is just a variable! # It contains the argument when the function was called. if target: hero.attack(target) hero.moveXY(43, 34) while True: hero.moveXY(58, 52) topEnemy = hero.findNearestEnemy() # Using the checkAndAttack function with the topEnemy variable. checkAndAttack(topEnemy) # Move to the bottom X mark. hero.moveXY(43, 34) hero.moveXY(58, 16) # Create a variable named bottomEnemy and find the nearest enemy. def checkAndAttack(target): # The 'target' parameter is just a variable! # It contains the argument when the function was called. if target: hero.attack(target) while True: bottomenemy = hero.findNearestEnemy() # Use the checkAndAttack function, and include the bottomEnemy variable. checkAndAttack(bottomEnemy)
you already defined checkAndAttack. Delete the second time you define it. You should also remove the second while true loop
i did that and nothing else happened
@Needs_lots_help is right. After you’ve deleted the second function and the second while true loop, make sure you put the checkAndAttack(target) function after you go to the bottom cross too. This is all meant to be inside one loop.
can you show me some sort of example
Here’s a bit of a hint:
- define the function. You’ve done that.
- make a while true loop, also done that.
- move to the top X make an enemy variable, done.
- use the function, done.
- Now move to the bottom X, done.
- Now do the same thing you did at the top X at the bottom.
Why don’t you try it first, think about it for a while, then come back.
# == means "is equal to". if 1 + 1 + 1 == 6: # ∆ Make this false. hero.moveXY(5, 15) # Move to the first mines. if 2 + 2 == 4: # ∆ Make this true. hero.moveXY(15, 40) # Move to the first gem. # != means "is not equal to". if 2 + 2 == 4: # ∆ Make this true. hero.moveXY(25, 15) # Move to the second gem. # < means "is less than". if 2 + 2 < 7: # ∆ Make this true. enemy = hero.findNearestEnemy() hero.attack(enemy) if 2 < 1: # ∆ Make this false. hero.moveXY(40, 55) if True:2 + 3 == 7 # ∆ Make this false. hero.moveXY(55, 24) if False: 3 + 3 == 6 # ∆ Make this true. hero.moveXY(55, 25)
That text is from a different level, why did you post it here?
If it is another level please make another topic.
Could I also say, please could you stop using so many @s it isn’t necessary because the people who will help you will see it anyway, unless you want one specific person. It also sends a notification which I (for one) don’t really want. If you want someone specifically @ them, but please don’t do it for lots of people at the start of each post.
Yes! That is EXACTLY what I wanted to say!