I frequently have this one problem that i seem to be unable to solve…
loop: enemy = self.findNearestEnemy() if enemy: distance = self.distanceTo(enemy) if distance > 5 : else: # this is line 15 self.shield() pass else: self.moveXY(40, 34)
original code for reference;
You can put one if-statement within another if-statement.
enemy = self.findNearestEnemy()
# If there is an enemy, then... if enemy: # Create a distance variable with distanceTo. # If the enemy is less than 5 meters away, then attack() # Otherwise (the enemy is far away), then shield() pass # Otherwise (there is no enemy...) else: # ... then move back to the X. self.moveXY(40, 34)
however, on line 15 it always says i have some kind of “unexpected token”
(BTW this is on the level Stillness in Motion)
someone please help!