Can someone help me?
The bug finder thing says “else: for-else statment unsupoorted”
and it doesn’t tell me what line its on.
Here’s my code. I’ve been struggling on this level for nearly 5 days now.
def commandArchers():
for archer in self.findByType(archer, self.findFriends()):
nearestEnemy = archer.findNearestEnemy()
if nearestEnemy:
self.command(archer, 'attack', nearestEnemy)
else:
hero.command(archer, 'defend', hero)
def commandSoldiers():
for soldier in self.findByType('soldier', self.findFriends()):
nearestEnemy = soldier.findNearestEnemy()
if nearestEnemy:
self.command(soldier, 'attack', nearestEnemy)
else:
hero.command(soldier, 'defend', hero)
def summonGriffins():
if hero.gold > hero.costOf('griffin-rider'):
hero.summon('griffin-rider')
def pick():
item = hero.findNearestItem()
flag = hero.findFlag()
if item:
hero.moveXY(item.pos.x, item.pos.y)
if flag:
hero.pickUpFlag(flag)
def commandGriffins():
for griffin in self.findByType('griffin-rider', self.findFriends()):
enemies = griffin.findEnemies()
nearestEnemy = self.findNearest(enemies)
if nearestEnemy:
self.command(griffin, 'attack', nearestEnemy)
else:
self.command(griffin, 'defend', self)
def weakestFriend():
weakestFriend = None
weakestHealth = 999
for friend in self.findFriends():
if friend.health < friend.maxHealth and friend.health < weakestHealth:
weakestHealth = friend.health
weakestFriend = friend
if weakestFriend:
return weakestFriend
def commandPaladins():
for paladin in self.findByType('paladin', self.findFriends()):
if paladin.canCast('heal', self):
if self.health < 3000:
self.command(paladin, 'cast', 'heal', self)
else:
weakestFriend2 = weakestFriend()
if weakestFriend2:
self.command(paladin, 'cast', 'heal', weakestFriend2)
else:
hero.command(paladin, 'defend', hero)
def summonGriffin():
if self.gold >= self.costOf('griffin-rider'):
self.summon('griffin-rider')
def moveForward():
targetPos = {"x": 328, "y": 35}
self.move(targetPos)
def pickTarget():
enemies = self.findEnemies()
target = None
minDistance = 9999
for enemy in enemies:
if enemy.type is not 'door':
if enemy.type is 'catapult':
target = enemy
break
elif enemy.type is 'warlock':
target = enemy
break
elif enemy.type is 'witch':
target = enemy
break
elif enemy.type is 'chieftain':
target = enemy
break
else:
if self.distanceTo(enemy) < minDistance:
minDistance = self.distanceTo(enemy)
target = enemy
if target:
return target
def commandHero():
target = pickTarget()
if target:
while target.health > 0:
if hero.canCast('chain-lightning', target):
hero.cast('chain-lightning', target)
if hero.isReady('stomp'):
hero.stomp()
elif hero.isReady('throw'):
hero.throw(target)
else:
self.attack(target)
hero.shield()
moveForward()
def attackCatapults():
catapults = self.findByType('catapult')
if len(catapults):
for catapult in catapults:
while catapult.health > 0:
self.attack(catapult)
while True:
pick()
summonGriffins()
commandPaladins()
commandArchers()
commandSoldiers()
commandGriffins()
pickTarget()
commandHero()
attackCatapults()