On Game Dev 2, it is not working. I am trying to track and increase the number of items collected. However, it is not working.
#Goals
game.addMoveGoalXY(28,28)
game.addMoveGoalXY(62, 11)
game.addMoveGoalXY(11,60)
game.addMoveGoalXY(61, 60)
game.addDefeatGoal(10)
game.addCollectGoal(5)
game.addSurviveGoal()
#Player
player = game.spawnPlayerXY("knight", 45, 15)
player.maxHealth=500
player.attackDamage=150
player.maxSpeed=1
#Setting
game.spawnMaze("forest", 4)
game.spawnXY("forest", 60, 42)
game.spawnXY("forest", 28, 20)
#Enemies
generator=game.spawnXY("generator", 60, 30)
generator.health=9001
generator.spawnType = "munchkin"
unit = player.findNearestEnemy
unit.maxSpeed=100
unit.attackDamage= 100
#Objects to Collect
game.spawnXY("gold-coin", 35, 12)
game.spawnXY("gold-coin", 60, 50)
game.spawnXY("gold-coin", 61, 18)
game.spawnXY("gold-coin", 60, 32)
game.spawnXY("mushroom", 13,40)
#track
ui.track(game, "defeated")
ui.track(game, "collected")
#Tracking
def onCollect(event):
item=player.findNearestItem
if item.type == "gold-coin":
game.collected += 1
game.on("collect", onCollect)