# 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)
# 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)
@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.
Danny
# == 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.