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

[SOLVED] Army Training 2, Python

Game Development 2, Army Training 2, Python

# Defeat the ogres using event handlers to command units.

# Spawn 2 "soldier"s.
game.spawnXY("soldier", 35, 20)
game.spawnXY("soldier", 45, 20)
# Spawn 2 "archer"s.
game.spawnXY("archer", 36, 22)
game.spawnXY("archer", 88, 12)
def fightEnemies(event):
    while True:
        # is the unit that is executing this event handler function!
        friendUnit =
        enemy = friendUnit.findNearestEnemy()
        # Have friendUnit attack() the enemy!

# This attaches the fightEnemies handler to all soldiers' "spawn" events.
game.setActionFor("soldier", "spawn", fightEnemies)

# Now, attach fightEnemies to the archers' "spawn" events:

Here put instead something like this:


After this put

if enemy:

And put this

In the if.
Does it work now?

1 Like

Yes, it worked. Thanks!