Need help at level 24. Thank you. Try to preformatted text

type or paste code here
```Preformatted text
ogre = game.spawnXY("munchkin",x,y)

Would you please send the link of the level?

Hi Aya

type or paste code here
https://codecombat.com/play/level/disintegration-arrow?course=57b621e7ad86a6efb5737e64&course-instance=62fc312a33504f003d022e0a

# Destroy at least 50 defeated ogres.

# This spawns and configures an archer.
def spawnArcher(x, y):
    archer = game.spawnXY("archer", x, y)
    archer.behavior = "Defends"
    archer.attackDamage = 20

# This spawns and configures an ogre.
def spawnMunchkin(x, y):
    ogre = game.spawnXY("munchkin", x, y)
    ogre.behavior = "AttacksNearest"

# Spawns some archers in a row.
def spawnArcherWall():
    spawnArcher(30, 12)
    spawnArcher(30, 23)
    spawnArcher(30, 34)
    spawnArcher(30, 45)
    spawnArcher(30, 56)

# Spawns an ogre wave with a random offset for variety.
def spawnOgreWave():
    offset = game.randomInteger(-6, 6)
    spawnMunchkin(80, 16 + offset)
    spawnMunchkin(80, 22 + offset)
    spawnMunchkin(80, 28 + offset)
    spawnMunchkin(80, 34 + offset)
    spawnMunchkin(80, 40 + offset)
    spawnMunchkin(80, 46 + offset)
    spawnMunchkin(80, 52 + offset)


def onDefeat(event):
    unit = event.target
    # Increase the game.defeated counter by 1.
    unit = event.target
    # Use unit.destroy() to destroy it.
    game.defeated += 1
    

# Set "munchkin"s "defeat" event handlers to onDefea
"munchkin""defeat"
game.defeated =0
game.spawnTime = 0
# Add a manual goal.
goal = game.addManualGoal("Defeat 77 ogres.")
ui.track(game, "defeated")

def checkSpawnTimer():
    if game.time > game.spawnTime:
        spawnOgreWave()
        game.spawnTime += 1

def checkGoal():
    # If the game.defeated counter is greater than 77:
    if (game.defeated > 111):
        # Set the goal as successfully completed.
        goal.success = True
    pass

spawnArcherWall()
while True:
    checkSpawnTimer()
    checkGoal()



1 Like

Im looking into it, just need some time

so the first line is right in this function, the second one make it as unit.destroy() and the third is fine

As for this one, you have to make it:
game.setActionFor("munchkin", "defeat", onDefeat)

this should be game.setGoalState(goal, True)

this should be 77

1 Like

Hi Aya

Thank you for your help. I passed the level.

You’re most welcome! Glad you did!

Would you please mark the solution so the topic would close? Thanks

3 Likes

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