ive been stuck for days here, i dont know what i am doing wrong ive tried like 30 totally different pieces of code. this is what ive ended up with now, the def(): pices have defined everything yet it says ogre isnt defined and then the yeti and then b (and c) (i do some pices of code saying yeti = 0 and ogre = 0 and c = hero.findNearestEnemy so that it is defined at the start and the code can fix it later and it just stops when the first guy is defeated
def findHealth():
for enemy in hero.findEnemies():
ogre = 0
yeti = 0
if enemy.type == "yeti":
yeti += enemy.health
else:
ogre += enemy.health
def nearYetiAttack():
for b in hero.findEnemies():
if b.type == "yeti":
bad = b
def nearOgreAttack():
for c in hero.findEnemies():
if c.type == "ogre" or "scout":
reallyBad = c
def findBest():
if ogre >= yeti:
nearYetiAttack()
for friend in hero.findFriends():
hero.command(friend, "attack", b)
else:
nearOgreAttack()
for friend in hero.findFriends():
hero.command(friend, "attack", c)
while True:
findHealth()
findBest()
i did this and they just stop like it wont define anything else
c = hero.findNearestEnemy()
b = hero.findNearestEnemy()
yeti = 0
ogre = 0
def findHealth():
for enemy in hero.findEnemies():
ogre = 0
yeti = 0
if enemy.type == "yeti":
yeti += enemy.health
else:
ogre += enemy.health
def nearYetiAttack():
for b in hero.findEnemies():
if b.type == "yeti":
bad = b
def nearOgreAttack():
for c in hero.findEnemies():
if c.type == "ogre" or "scout":
reallyBad = c
def findBest():
if ogre >= yeti:
nearYetiAttack()
for friend in hero.findFriends():
hero.command(friend, "attack", b)
else:
nearOgreAttack()
for friend in hero.findFriends():
hero.command(friend, "attack", c)
while True:
findHealth()
findBest()
i now have everything running through each other so in order to get to one part you need to define another and it still says “ogre is not defined”
def findHealth():
for enemy in hero.findEnemies():
ogre = 0
yeti = 0
if enemy.type == "yeti":
yeti += enemy.health
else:
ogre += enemy.health
def nearYetiAttack():
bad = hero.findByType("yeti")
if bad:
b = hero.findNearest(bad)
for friend in hero.findFriends:
hero.command(friend, "attack", b)
def nearOgreAttack():
reallyBad = hero.findByType("brawler")
if reallyBad:
c = hero.findNearest(reallyBad)
for friend in hero.findFriends:
hero.command(friend, "attack", c)
def findBest():
findHealth()
if ogre >= yeti:
nearYetiAttack()
for friend in hero.findFriends():
hero.command(friend, "attack", b)
else:
nearOgreAttack()
for friend in hero.findFriends():
hero.command(friend, "attack", c)
while True:
findBest()
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)
while True:
notOk = hero.findNearest(hero.findByType("Headhunter" or "Ogre" or "Brawler"))
if notOk:
ifBrawler()
else:
pickUpNearestCoin()
summonSoldier()
commandSoldiers()
it goes straight to pickUpNearestCoin() even if there are brawlers or ogres or headhunters. Its like it wont look, and yes, i started off not capitalizing the ogre or headhunter etc (you can put multiple things in findbytype right?
looks like you should add bad.health >= reallyBad.health then on lines 3(just after the if bad part)
and vice versa for line 9(so reallyBad.health >= bad.health and so on)