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

Return statement TROUBLE

Hi, I am struggling witha return statement.
Here is my code.
Can someone tell me what i did wrong? My hero doesnt have an error, but isnt summoning.
Code Here.

summonTypes = ['soldier', 'soldier', 'archer', 'decoy']
def summon():
    type = summonTypes[len(hero.built) % len(summonTypes)]
    return type
def commandPeasant():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == 'peasant':
            if (summon == 'decoy') and > 25:
                hero.command(friend, "buildXY", 'decoy', friend.pos.x, friend.pos.y)
                items = hero.findItems()
                item = friend.findNearest(items)
                if item:
                    hero.command(friend, "move", item.pos)
def commandSoldier():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == 'archer':
            enemies = hero.findEnemies()
            target = friend.findNearest(enemies)
            if target:
                hero.command(friend, "attack", target)
def commandArcher():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == 'soldier':
            targets = hero.findByType("archer", hero.findEnemies())
            target = friend.findNearest(targets)
            if target:
                hero.command(friend, "attack", target)
                enemies = hero.findEnemies()
                enemy = friend.findNearest(enemies)
                if enemy:
                    hero.command(friend, "attack", enemy)
def T():
    if (summon == 'soldier') and > 20:
    if (summon == 'archer') and > 25:
def attack():
    item = hero.findNearestItem()
    if item:
while True:

Is this level steelClaw Gap?

1 Like

No. It is a custom level

I don’t think I can help with that, but others may be able to help you if you send
the link.

if (summon == 'soldier')

I believe you’re trying to call the function summon, in which case you need the parenthesis.

if (summon() == 'soldier')

Otherwise you are comparing the function summon to the string 'soldier', which of course is never true.

The function T (which needs a more descriptive name, by the way) can be rewritten more efficiently by reusing the return value of summon:

def summonUnit():
    unitType = summon()
    if > hero.costOf(unitType):
1 Like

Thank you so much!!!

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.