it seems im needing alot of these
my hero never attacks any headhunter or brawler or ogre (im going to call these the big 3) even though it is before my soldiers are commanded to attack alsi ive known how to use def(): for a long time so why does the level say “this level helps you learn how to define you own functions”
def pickUpNearestCoin():
items = hero.findItems()
nearestCoin = hero.findNearest(items)
if nearestCoin:
hero.move(nearestCoin.pos)
def summonSoldier():
if hero.gold >= hero.costOf("soldier"):
hero.summon("soldier")
pass
def ifBrawler():
bad = hero.findNearest(hero.findByType("Brawler" or "Headhunter" or "Ogre"))
if bad and hero.distanceTo(bad) < 8:
hero.consecrate()
hero.attack(bad)
elif bad:
hero.attack(bad)
def commandSoldiersAndMe():
notOk = hero.findByType("brawler")
alsoBad = hero.findByType("headhunter")
notGood = hero.findByType("ogre")
if notOk or notGood or alsoBad:
if notOk:
attack1 = hero.findNearest(notOk)
if attack1 and hero.distanceTo(attack1) < 5:
hero.consecrate()
hero.attack(attack1)
elif attack1:
hero.attack(attack1)
elif alsoBad:
attack3 = hero.findNearest(alsoBad)
if attack3 and hero.distanceTo(attack3) < 5:
hero.consecrate()
hero.attack(attack3)
elif attack3:
hero.attack(attack3)
elif notGood:
attack2 = hero.findNearest(notGood)
if attack2 and hero.distanceTo(attack2) < 5:
hero.consecrate()
hero.attack(attack2)
elif attack2:
hero.attack(attack2)
for soldier in hero.findFriends():
enemy = soldier.findNearestEnemy()
if enemy:
hero.command(soldier, "attack", enemy)
while True:
pickUpNearestCoin()
summonSoldier()
commandSoldiersAndMe()