I rly need help (borrowed sword)

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()

help

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()

ive given up im now just killing the yetis because theyre winning

while True:
    yeti = hero.findNearest(hero.findByType("yeti"))
    if yeti:
        for friend in hero.findFriends():
            hero.command(friend, "attack", yeti)

What level are you stuck on?

Oh i thought i mentioned borrowed sword
sorry

wait i am going to go do something

i realized some of my code was repeating itself and trying to attack twice so i fixed that i was tired lol

def nearYetiAttack():
    bad = hero.findNearest(hero.findByType("yeti"))
    if bad:
        for friend in hero.findFriends:
            hero.command(friend, "attack", bad)

def nearOgreAttack():
    reallyBad = hero.findNearest(hero.findByType("brawler"))
    if reallyBad:
        for friend in hero.findFriends:
            hero.command(friend, "attack", reallyBad)

def findBest():
    for enemy in hero.findEnemies():
        ogre = 0
        yeti = 0
        if enemy.type == "yeti":
            yeti += enemy.health
        else:
            ogre += enemy.health
    if ogre >= yeti:
        nearOgreAttack()
    else:
        nearYetiAttack()

while True:
    findBest()

Now there are no errors but it still kills brawlers even thought the yetis clearly have more health

and i also have a problem with another level.

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?

edit: creating another topic for this

link? i cant seem to find the level

nvm i found the level looking into it :+1:

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)

thank you ill try it