Hi, I talk Spanish but all the people here talk in English, so I’ll talk you my problem in English. I have a trouble with this level, my code is:
def pickUpCoin():
coin = hero.findNearestItem()
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)
Write the attackEnemy function below.
Find the nearest enemy and attack them if they exist!
def findandattackenemy():
hero.findNearestEnemy()
if enemy:
hero.attackEnemy
while True:
attackEnemy = self.findNearestEnemy() # ∆ Uncomment this line after you write an attackEnemy function.
pickUpCoin()
I don’t know what’s the problem if any have the solution give me this please
Like Bryukh said, please format your question. Because we can not tell the indents of our code, and considering Python uses the indents it is important.
This is my function. The game say that i needed to find the nearest enemy and then if the enemy exist attack him but this function don’t respond.
The problem is that my hero begins to collect the money and then the enemy stands in front of my hero collecting the coins first. Do you have any function for me that it respond?
# Write a function to squash them before they can take your coins.
def pickUpCoin():
coin = hero.findNearestItem()
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)
# Write the attackEnemy function below.
# Find the nearest enemy and attack them if they exist!
enemy = hero.findNearestEnemy()
def attackEnemy():
if enemy:
hero.attack(enemy)
while True:
attackEnemy() # ∆ Uncomment this line after you write an attackEnemy function.
pickUpCoin()
thats my code idk what the problem is with the code it doesn't work the peons always get my coins
# Peons are trying to steal your coins!
# Write a function to squash them before they can take your coins.
def pickUpCoin():
coin = hero.findNearestItem()
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)
# Write the attackEnemy function below.
# Find the nearest enemy and attack them if they exist!
def attackEnemy():
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
while True:
attackEnemy() # ∆ Uncomment this line after you write an attackEnemy function.
pickUpCoin()