Need help on guard duty[SOLVED]

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:

image

This is a typo. As the error says, you need a valid type string to spawn. Further down in your code you use “soldier”. That is the correct string to use.
Danny

1 Like

i did but now this happens
image

2 Likes

i solved it myself

2 Likes

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