I’m on game Development 2 in code combat and my code won’t work because it says that “cannot read property “on” of “undefined””. here’s my code:
ui.track(game, “defeated”)
game.defeated = 0
player.on(“defeat”, onDefeat)
def onDefeat (event):
unit = event.target
item = event.other
if unit.type == “munckin” :
game.defeated += 1
player = game.spawnPlayerXY(“samurai”, 36, 30)
player.maxHealth = 65000
ui.track(game, “time”)
ui.track(player, “health”)
game.spawnXY(“forest”, 67, 24)
game.spawnXY(“forest”, 58, 24)
game.spawnXY(“forest”, 67, 32)
game.spawnXY(“forest”, 54, 24)
game.spawnXY(“forest”,13, 32)
game.spawnXY(“forest”, 20, 32)
generato = game.spawnXY(“generator”, 14, 22)
generator = game.spawnXY(“generator”, 57, 32)
generator.spawnType = “munchkin”
generato.spawnType = “munchkin”
fireSpewer = game.spawnXY(“fire-spewer”, 11, 10)
fireSpewer = game.spawnXY(“fire-spewer”, 11, 11)
fireSpewer = game.spawnXY(“fire-spewer”, 11, 12)
fireSpewer = game.spawnXY(“fire-spewer”, 11, 13)
fireSpewer = game.spawnXY(“fire-spewer”, 11, 14)
fireSpewer.spawnEvery = 0.25
potionSmall = game.spawnXY(“potion-small”, 67, 40)
potionSmall = game.spawnXY(“potion-small”, 15, 40)
game.spawnXY(“mushroom”, 67, 13)