Help cages game dev 2

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 =
    if unit.type == "scout":
        game.scoutsSpawned += 1
    if game.scoutsSpawned >= 3:
        # Defeat scoutGenerator with the defeat() method.
        # Destroy rightFence with the destroy() method.
    if unit.type == "munchkin":
        game.munchkinsSpawned += 1
    if game.munchkinsSpawned >= 2:
        # Defeat munchkinGenerator.
        # Destroy the leftFence.
        destroy(leftFence )

def onDefeat(event):
    unit =
    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)

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

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

is it different for javascript? cause I notice there are hashtags which means that this is python, and the defeat() isn’t working for me, should I try destroy?

same with me @ducky!

It says as one of the goals you should defeat 2 generators so do I do munchkinGenerator.defeat???

hi this is my code

right here @ducky you have to change the "defeat(scoutGenerator), destroy(rightFence),defeat(munchkinGenerator), and destroy(leftFence) into scoutGenerator.defeat(),rightFence.destroy(),munckinGenerator.defeat(), and leftFence.destroy() to complete the level

Hi. Ducky is not active anymore so your just wasting a post.

oh really@Eric_Tang?

does that mean he is not in the forum anymore?

Well . . . Yes and no. Yes he does not come on the forum anymore but no, his account is not deleted.

ok thanks for the tip(Is that actually a tip IDK but I gues it is

1 Like