Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Hero wont summon and gettin an error

Ok…where are you calling summonTroops? That is where a paladin would be created/summoned and therefore defined.

in my while true loop, and it’s the first function i call

heh…what while true loop? I see only definitions.

He pasted only part of his code.

I noticed :wink:

Needs, please post the whole thing.

Ok, time to step out. I’m just being stupid.

Nope…keep me honest!

@Needs_lots_help, btw, what equipment do you have? Please post a pic of your inventory.

ok coming up with them rn

full code:

def summonTroops():
    summonTypes = ['paladin', "archer"]
    summonType = summonTypes[len(hero.built) % len(summonTypes)]
    if < hero.costOf(summonType):

def commandTroops(friends):
    lowest = lowestHealthUnit(friends)
    for friend in friends:
        enemy = friend.findNearestEnemy()
        #Here is where I sepereate between my archers and my paladins
        if friend.type == "paladin":
            paladin = friend
        if friend.type == 'archer':
            archer = friend
    if paladin.canCast("heal", lowest):
        #This is where my error of paladins not being defined yet occurs
        hero.command(paladin, "cast", "heal", lowest)
    if enemy:
        hero.command(archer, "attack", enemy)

def lowestHealthUnit(friends):
    lowestHealth = 999
    lowestUnit = None
    for friend in friends:
        if < lowestHealth:
            lowestUnit = friend
            lowestHealth =
    return lowestUnit

def pickUpCoin():
    coin = hero.findNearestItem()
    if coin:
        hero.moveXY(coin.pos.x, coin.pos.y)

while True:
    enemy = hero.findNearestEnemy()
    friends = hero.findFriends()

its just my functions wrapped in a while loop and I waited for my functions to be fixed before I make my hero start to do things.

it was actually a sapphire sense stone too I accidently uneqquipped

What is the actual level name/link? I’ll try running with your code.

backwoods brawl im just getting some gems to fully equip my hero with that dragon armor.

Which level are you at in the brawl? I’m at 4, so cannot regress, but my test login may be able to do your level.

ima be real with you chief I just started doing this because Ive been neglecting most replayable levels. I just been trying to make a decent program that can last me for a bit.

No worries…but, I still need to know which level of the brawl you are on. The flag for it, on the map, will have a number…what is that number? Or, in the level itself, you will see:

the 4 is the indicator.

Sorry for being unclear. From the whole thing I said, I meant to say 0

@dedreous bro you there?

Hi, I’ve noticed a few errors by looking at your code. Firstly this line:

I think that one will probably jump out at you. :grin:
Secondly: although this may not be an error, I think your for-loop for commanding the troops is a little bit… iffy. It just looks like it’s about to cause an error, to me, at least. I might suggest an alternative to differentiate between your archers and your paladins:

for friend in friends:
    enemy = hero.findNearestEnemy()
    if friend.type == "paladin":
        if paladin.canCast("heal", lowest):
            hero.command(paladin, "cast", "heal", lowest)
    elif friend.type == "archer":
        if enemy:
            hero.command(archer, "attack", enemy)

Another note, just for tactics, I would make your paladins shield when they’re not healing. It will make them last about 5x longer.
I hope this helps,

1 Like

I am now :wink:

Turns out, my test account is on level 5, so gonna have to wing it.

@Deadpool198, good catch!..I was so busy trying to see if I could duplicate, I didn’t see that one, right off.

thanks guys for your help. I checked in on this and I fixed my code by adding some archer and paladin functions and my code worked out well. Gonna see how many levels my hero can last.