this is my code:
# Voeg een soldaat toe aan het level om ogres tegen te houden.
# Beveel de soldaat door een event handler functie te gebruiken.
def munchkinLogic():
while True:
enemy = munchkin.findNearestEnemy()
if enemy:
munchkin.attack(enemy)
munchkin = game.spawnXY("munchkin", 0, 28)
munchkin.on("spawn", munchkinLogic)
def soldierLogic():
# Type hier de code voor de acties van de soldaat.
# Onthoud dat je nu 'soldier' gebruikt in plaats van 'hero'!
while True:
enemy = soldier.findNearestEnemy()
game.spawnXY("soldoer", 42, 48)
# Val de vijand aan, als er een vijand is.
if enemy:
# Units have the attack() method.
# Use soldier.attack(enemy) method:
soldier.attack(enemy)
pass
# Anders ga je terug naar de start positie.
else:
# Units have the moveXY() method.
soldier.moveXY(42, 48)
pass
# Dit geeft je gespawnde troep de soldier variabele.
soldier = game.spawnXY("soldier", 42, 48)
game.spawnXY("munchkin", 36, 30)
# Dit zegt dat de soldierLogic functie moet worden uitgevoerd wanneer de soldaat gespawned wordt.
soldier.on("spawn", soldierLogic)
munchkin.on("spawn", munchkinLogic)
problem: