The level seems to produce random errors regarding functions.
It says hero has no method findFriends for example. It would also not accept hero.toggleFlowers(True) for the same reason at the beginning of the code.
here is my code so far:
# Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
hero.toggleFlowers(True)
def lowestHealth():
lowestHealth = 99999
lowestFriend = None
friends = hero.findFriends()
for friend in friends:
if friend.health < lowestHealth and friend.health < friend.maxHealth:
lowestHealth = friend.health
lowestFriend = friend
return lowestFriend
def commandPaladin(paladin):
weakFriend = lowestHealth()
enemy = paladin.findNearestEnemy()
if weakFriend and paladin.canCast("heal", weakFriend):
hero.command(paladin, "cast", "heal", weakFriend)
elif paladin and paladin.health <200:
hero.command(paladin, "shield", paladin)
else:
hero.command(paladin, "attack", enemy)
pass
def commandArcher(archer):
thrower = hero.findByType("catapult")
enemy = archer.findNearest(enemies)
for friend in friends:
if thrower:
hero.command(archer, "attack", catapult)
else:
hero.command(archer, "attack", enemy)
def commandSoldier(soldier):
for friend in friends:
hero.command(friend, "attack", enemy)
def hero():
if enemy and hero.isReady("cleave"):
hero.cleave(enemy)
elif enemy:
hero.attack(enemy)
elif hero.pos.x < 100:
hero.attack({'x':101,'y':36})
elif hero.pos.x < 150:
hero.attack({'x':159,'y':36})
elif hero.pos.x < 270:
hero.attack({'x':288,'y':36})
def commandFriends():
friends = hero.findFriends()
for friend in friends:
if friend.type == "archer":
commandArcher(friend)
pass
elif friend.type == "Soldier":
commandSoldier(friend)
pass
elif friend.type == "paladin":
commandPaladin(friend)
while True:
commandFriends()
if hero.gold > hero.costOf("archer"):
hero.summon("archer")
friends = hero.findFriends()
if friends:
for friend in friends:
if friend and friend.health < lowestHealth and friend.health < friend.maxHealth:
lowestHealth = friend.health
lowestFriend = friend
I think you should write: if weakFriend and paladin.canCast("heal"):
I dont think, that you should write “paladin” after shield.
Maybe elif enemy:?
I think you should remove “for”. Also, “thrower” is array, “catapult” and “enemies” are undefined. Where is if enemy:?
What is “enemy”? It’s undefined. And maybe hero.command(soldier,"attack",enemy), and you don’t need “for”?
Again “enemy” is undefined. And I don’t think, that you can attack position.
if friends:? if friend:?
Do you mean “soldier”?
Where is hero() function?
And I don’t think, that you can pass this level with your equipment. I think you need better sword and helmet.
Dima
I don’t know why does this cause an error, but try to write if friends:, it can work, because sometimes it says an error, that doesn’t exist, instead of true error.
Dima