Sowing fire python

he commandattack function

The issue is that you probably didn’t iterate through them properly, but it should look like this:

for friend in hero.findFriends():
        enemy = friend.findNearestEnemy()
        if enemy:
            hero.command(friend, 'attack', enemy)

still not working same error as last time

Could you please post your most recent code again?
Grzmot

# Goal: build three rows of nine fire-traps.

# Returns "retreat", "attack", "start-next-trap-column", or "build-next-trap-in-column"
def chooseStrategy():
    enemies = hero.findEnemies()
    
    # If there are overwhelming ogre forces, return the "retreat" strategy.
    if len(enemies) > 20:
        return "retreat"
    
    # If there are some ogres, return the "attack" strategy.
    if len(enemies) > 0:
        return "attack"
    # Use x % 9 is 0 to see if x is divisible by 9.
    # Use len(self.built) to see how many traps you have built.
    # If you have finished a column of 9 traps, return "start-next-trap-column"
    if len(self.built) % 9 == 0:
        return "start-next-trap-collumn"
    # Otherwise, return "build-next-trap-in-column"
    else:
        return "build-next-trap-in-column"

trapsInColumn = 9
startX = 40
columnX = startX

# Build the next trap in a column in the correct place.
def buildNextTrapInColumn(columnX,numTraps):
    # Change newY to use % to wrap around and only build trapsInColumn (9) traps per column
    newY = 7 * (numTraps % 9) + 10 # ∆ Change this to use % 9!
    if hero.pos.y > newY:
        hero.move({"x": columnX - 5, "y": newY})
    else:
        buildTrap(columnX,newY)

# Start a new column of traps.
def startNextTrapColumn(columnX, numTraps):
    newX = startX - (Math.floor(numTraps / trapsInColumn) * 6)
    if hero.pos.y > 10:
        hero.move({"x": newX - 5, "y": 10})
        return columnX
    else:
        buildTrap(newX,10)
        return newX

def buildTrap(x, y):
    hero.buildXY("fire-trap", x, y)

def commandAttack():
    # Have your griffin riders fend off the attackers.
    for friend in hero.findFriends:
        enemy = friend.findNearestEnemy()
        if enemy:
            hero.command(friend, "attack", enemy)
    pass

def commandRetreat():
    hero.say("Retreat!")
    # You and your griffin riders retreat to safety behind the traps.
    hero.command(friend, "move", {"x": 4, "y": 42})
    hero.moveXY(4, 42)

while True:
    strategy = chooseStrategy()
    if strategy == "attack":
        commandAttack()
    elif strategy == "build-next-trap-in-column":
        buildNextTrapInColumn(columnX, len(hero.built))
    elif strategy == "start-next-trap-column":
        columnX = startNextTrapColumn(columnX, len(hero.built))
    elif strategy == "retreat":
        commandRetreat()

The hero.findFriends isn’t actually a function, you need to have the parenthesis, like this:

hero.findFriends()

I saw that you went and started working on another topic, did you finish the level?
Grzmot

This was fun to watch, @Grzmot you only just missed a simple error.

if len(self.built) % 9 == 0:
    return "start-next-trap-collumn"

Column is spelled wrong here, yet spelled right when calling the strategy function. Change collumn to column.

-Gray

Nice! I missed that :joy:. The other issues also would have screwed up the coding but that is one more issue I missed.
Grzmot

@cheddarcheese, did you finish the level or just give up for now?
Grzmot

i gave up for now(20 chars)

Did you try everything we said and it still didn’t work?
Grzmot

yep im kinda thinking on starting over

I think that you got pretty close, so if you want to post your latest code i’d keep on looking for issues
Grzmot