[SOLVED] Game development 2 chokepoint

I get this error here is the error and the code

 Ogres are advancing through the forest lanes!
# Spawn some soldiers and have them defend their lanes!

def defendLane(event):
    # Remember to create a variable for the target, to remember:
    unit = event.target
    # Save the unit's starting pos.x
    startX = unit.pos.x
    while True:
        enemy = unit.findNearestEnemy()
        # If there is an enemy.
        if enemy:
            # Use unit.attack to attack the enemy:
            unit.attack(enemy)
            pass
        else:
            # Move the unit back to it's starting x and y.
            unit.moveXY(startX, 16)
        

game.spawnXY("soldier", 9, 16)
game.spawnXY("soldier", 30, 16)
game.spawnXY("soldier", 54, 16)
game.spawnXY("soldier", 75, 16)

# Set the event handler defendLane on "spawn" event for "soldier"s.
defendLane("spawn", "soldier")

Try refreshing the page @Eric_Tang

That didn’t work 20 chars

I have the same code as you and it worked

That’s wiered 20 chars

Can you send a link?
Lydia

here @Lydia_Song https://codecombat.com/play/level/chokepoint?

Replace this:

with this:
game.setActionFor("soldier", "spawn", defendLane)

Lydia

Thanks Lydia!! It worked Great :grin:

1 Like

Glad to help!
Lydia
20 chars

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