Help cages game dev 2


#1

Help! I can’t do this level because it says “Defeat is not defined”\/\/\/\/\/\/\/\/

# Learn the difference between destroy and defeat.

# Spawn the enemies.
ogre1 = game.spawnXY("ogre", 12, 18)
ogre1.behavior = "AttacksNearest"
ogre2 = game.spawnXY("ogre", 68, 50)
ogre2.behavior = "AttacksNearest"

munchkinGenerator = game.spawnXY("generator", 12, 50)
munchkinGenerator.spawnAI = "Scampers"
munchkinGenerator.spawnType = "munchkin"

scoutGenerator = game.spawnXY("generator", 68, 12)
scoutGenerator.spawnAI = "Scampers"
scoutGenerator.spawnType = "scout"

# The fences which we will destroy later.
leftFence = game.spawnXY("fence", 26, 14)
rightFence = game.spawnXY("fence", 54 , 50)

player = game.spawnPlayerXY("raider", 40, 34)
player.maxSpeed = 55
player.attackDamage = 60

# The global game counters.
game.scoutsSpawned = 0
game.munchkinsSpawned = 0
game.bossesDefeated = 0
ui.track(game, "scoutsSpawned")
ui.track(game, "munchkinsSpawned")
ui.track(game, "bossesDefeated")

bossesGoal = game.addManualGoal("Defeat 2 big ogres.")

def onSpawn(event):
    unit = event.target
    if unit.type == "scout":
        game.scoutsSpawned += 1
    if game.scoutsSpawned >= 3:
        # Defeat scoutGenerator with the defeat() method.
        defeat(scoutGenerator)
        # Destroy rightFence with the destroy() method.
        destroy(rightFence)
        pass
    if unit.type == "munchkin":
        game.munchkinsSpawned += 1
    if game.munchkinsSpawned >= 2:
        # Defeat munchkinGenerator.
        defeat(muchkinGenerator)
        # Destroy the leftFence.
        destroy(leftFence )
        pass

def onDefeat(event):
    unit = event.target
    if unit.type == "ogre":
        # Increase the game.bossesDefeated counter by 1:
        game.bossesDefeated += 1

game.setActionFor("munchkin", "spawn", onSpawn)
game.setActionFor("scout", "spawn", onSpawn)
game.setActionFor("ogre", "defeat", onDefeat)

while True:
    if game.bossesDefeated >= 2:
        game.setGoalState(bossesGoal, True)


#2

You have to do it like this @ducky
scoutGenerator.destroy()
and
rightFence.destroy()
You have to name the thing before the dot then you put the action afterwards. Its very similar to Hero.attack()


#3

Thank you for your help, but it still has the same message- except it has no idea what munchkinGenerator is.