Help with summit's gate please

it says that bigFriend is undefined on line 45
here’s my code:

def commandTroops(troops):
    for troop in troops:
        violet = hero.findFlag("violet")
        enemy = troop.findNearestEnemy()
        lowest = None
        lowestNum = 99999
        for troop in troops:
            if troop.health < lowestNum:
                lowestNum = troop.health
                lowest = troop
        if lowest and violet and troop.type == "paladin" and troop.canCast("heal"):
            hero.command(troop, "cast", "heal", lowest)
            hero.move(violet.pos)
            hero.pickUpFlag(violet)
        elif enemy and hero.time < 30:
            hero.command(troop, "attack", enemy)
        elif enemy and enemy.pos.x < troop.pos.x + 30:
            hero.command(troop, "attack", enemy)
        else:
            hero.command(troop, "move", {"x":hero.pos.x, "y":hero.pos.y})

def summonTroops():
    if hero.gold >= hero.costOf("soldier"):
        hero.summon("soldier")

def heroActions():
    green = hero.findFlag("green")
    violet = hero.findFlag("violet")
    enemy = hero.findNearestEnemy()
    if green:
        hero.move(green.pos)
        hero.pickUpFlag(green)
    elif violet and hero.canCast("regen", hero):
        hero.move(violet.pos)
        hero.cast("regen", hero)
        hero.pickUpFlag(violet)
    friends = hero.findFriends()
    bigFriend = None
    maxHealth = 0
    for friend in friends:
        if friend.health > maxHealth:
            maxHealth = friend.health
            bigFriend = friend
    if bigBoi and hero.canCast("grow", bigFriend):
        hero.cast("grow", bigFriend)
    elif enemy and enemy.type == "catapult":
        hero.attack(enemy)
    elif enemy and enemy.pos.x < hero.pos.x + 45:
        hero.attack(enemy)
    friends = hero.findFrinends
    commandTroops(friends)
    summonTroops()

while True:
    heroActions()

thanks for your help

that would be this line:

(by the way i saw the variable that’s wrong nut i changed that in my code and it still doesn’t work)

Could you post your new code?
Thanks
Danny

here it is:

def commandTroops(troops):
    for troop in troops:
        violet = hero.findFlag("violet")
        enemy = troop.findNearestEnemy()
        lowest = None
        lowestNum = 99999
        for troop in troops:
            if troop.health < lowestNum:
                lowestNum = troop.health
                lowest = troop
        if lowest and violet and troop.type == "paladin" and troop.canCast("heal"):
            hero.command(troop, "cast", "heal", lowest)
            hero.move(violet.pos)
            hero.pickUpFlag(violet)
        elif enemy and hero.time < 30:
            hero.command(troop, "attack", enemy)
        elif enemy and enemy.pos.x < troop.pos.x + 30:
            hero.command(troop, "attack", enemy)
        else:
            hero.command(troop, "move", {"x":hero.pos.x, "y":hero.pos.y})

def summonTroops():
    if hero.gold >= hero.costOf("soldier"):
        hero.summon("soldier")

def heroActions():
    green = hero.findFlag("green")
    violet = hero.findFlag("violet")
    enemy = hero.findNearestEnemy()
    if green:
        hero.move(green.pos)
        hero.pickUpFlag(green)
    elif violet and hero.canCast("regen", hero):
        hero.move(violet.pos)
        hero.cast("regen", hero)
        hero.pickUpFlag(violet)
    friends = hero.findFriends()
    bigFriend = None
    maxHealth = 0
    for friend in friends:
        if friend.health > maxHealth:
            maxHealth = friend.health
            bigFriend = friend
    if bigFriend and hero.canCast("grow", bigFriend):
        hero.cast("grow", bigFriend)
    elif enemy and enemy.type == "catapult":
        hero.attack(enemy)
    elif enemy and enemy.pos.x < hero.pos.x + 45:
        hero.attack(enemy)
    friends = hero.findFrinends
    commandTroops(friends)
    summonTroops()

while True:
    heroStuff()

sorry about the function in the while loop i change it and it doesn’t work

Do you still have the same error? It looks like you have checked if bigFriend exists now.
You’ve got some typos:

and

I also think your tactic may cause problems (using flags inside the functions). I’m not sure but I don’t think I’ll be able to fix that, I think you may need to do a bit of testing and maybe change tactic to something a bit more simple.
Danny

thanks. i’ll try to have the flags in the while loop

@Deadpool198, it says that i need an object for this part of the code:

can you help me out?

Maybe you bigFriend is not an unit so you can’t cast spells on them?

i named it with this:

is there any mistake?

I will let @Deadpool198 or @dedreous to help you because @Deadpool198 was the first one to help you and because I do not have much experiece with wizards.

1 Like

ok. thanks :smile: :wink:

1 Like

@Deadpool198, it says that my hero.cast(“grow”, friend) line needs an object. why is that?

here’s my code:

def commandTroops(troops):
    for troop in troops:
        violet = hero.findFlag("violet")
        enemy = troop.findNearestEnemy()
        lowest = None
        lowestNum = 99999
        for troop in troops:
            if troop.health < lowestNum:
                lowestNum = troop.health
                lowest = troop
        if lowest and violet and troop.type == "paladin" and troop.canCast("heal"):
            hero.command(troop, "cast", "heal", lowest)
            hero.move(violet.pos)
            hero.pickUpFlag(violet)
        elif enemy and hero.time < 30:
            hero.command(troop, "attack", enemy)
        elif enemy and enemy.pos.x < troop.pos.x + 30:
            hero.command(troop, "attack", enemy)
        else:
            hero.command(troop, "move", {"x":hero.pos.x, "y":hero.pos.y})

def summonTroops():
    if hero.gold >= hero.costOf("soldier"):
        hero.summon("soldier")

def heroActions():
    enemy = hero.findNearestEnemy()
    friends = hero.findFriends()
    bigFriend = None
    maxHealth = 0
    for friend in friends:
        if friend.type == "paladin" and hero.canCast("grow", friend):
            hero.cast("grow", friend)
    if enemy and enemy.type == "catapult":
        hero.attack(enemy)
    elif enemy and enemy.pos.x < hero.pos.x + 45:
        hero.attack(enemy)
    friends = hero.findFriends
    commandTroops(friends)
    summonTroops()

while True:
    green = hero.findFlag("green")
    violet = hero.findFlag("violet")
    black = hero.findFlag("black")
    if green:
        hero.move(green.pos)
        hero.pickUpFlag(green)
    elif violet and hero.canCast("regen", hero):
        hero.move(violet.pos)
        hero.cast("regen", hero)
        hero.pickUpFlag(violet)
    elif black and hero.canCast("summon-burl"):
        hero.move(black.pos)
        hero.cast("summon-burl")
        hero.pickUpFlag(black)
        
    heroActions()

Have you checked if there’s a friend?
Danny

hi @Deadpool198. i just did but apparently on this line:

commandTroops(friends)

there is no object. why is that?

1 Like

Maybe because you haven’t put brackets on this line:
hero.findFriends
Danny

1 Like

thanks :grin: (20 chars)

1 Like

for some reason, i can’t get the soldiers to move and my hero does s weird thing:
move to a random space

1 Like

I think the soldiers aren’t moving because you use the same variable “troop” in both for loops. Use a different one for the second.
I think your hero is moving randomly because you’re casting grow on a friend without checking the distance to the friend. Grow has a range. Make sure your friend is inside it.
Danny

1 Like