loop:
enemy = self.findNearestEnemy()
if enemy and self.distanceTo(enemy) < 10:
# Move to the left by subtracting 10 from your X coordinate.
pass
x = self.pos.x - 10
y = self.pos.y
self.moveXY(x, y)
else:
# Move to the right by adding 10 to your X coordinate.
pass
x = self.pos.x + 10
y = self.pos.y
self.moveXY(x, y)
First, when posting code, make sure you help us help you by formatting your code. You can do this by properly indenting and placing 3 tick marks (```) above and below your code.
Looking at your code, you aren’t exactly following the instructions:
For the first 10 secs ( self.now() <= 10 ), you must fight. This means find an enemy and attack it.
After that, you must collect coins until 30 seconds has passed ( self.now() <= 30), Find the nearest item to move to each coin.
After that, you must fight again.
Until you learn to do this, your ally will continue to die.
while True:
# If it’s the first 10 seconds, fight.
if hero.now() < 10:
hero.attack(enemy)
pass
# Else, if it’s the first 30 seconds, collect coins.
elif hero.now() < 30:
if item:
pos = itemipos
x = pos.x
y = pos.y
hero.moveXY(x, y)
pass
# After 30 seconds, join the raid!
else:
hero.attack(enemy)
pass