Tough Collector Help

I am working with my 12yo son on CodeCombat.

I have checked the code as carefully as I can, but I still keep getting this ‘unhandled error’ message.

Please help!

# In this level, you'll click on robots to defeat them and protect the peasant.
# Read to see how the program works.
# Follow the instructions.
# Then, play the game. 

# This code created the environment:

# This creates generators to spawn big robots.
# The generators are outside the screen,
# so they seem invisible:
game.spawnXY("generator", -10, 34)
game.spawnXY("generator", 90, 34)
game.setPropertyFor("generator", "spawnType", "robobomb")
game.setPropertyFor("generator", "spawnRadius", 10)
game.setPropertyFor("robobomb", "scale", 2)

# We also spawn a big peasant, and some coins and potions.
# The peasant will collect the coins:
game.spawnXY("peasant", 40, 34)
game.setPropertyFor("peasant", "scale", 2)
game.spawnRandomly("gold-coin", 20)
game.spawnRandomly("potion-large", 4)
game.setPropertyFor("peasant", "behavior", "Collects")

# Your turn.
# The peasant needs to be healthy to survive the robots. 
# Set its "maxHealth" property to at least 5000:
game.setPropertyFor("peasant", "maxHealth", 6000)

# Now let’s add events and handlers.
# Robobombs have 200 health points. 
# We want it to take two clicks to defeat them
# So, we assign 100 points of damage for each click event:
game.onInput("click", handler.takeDamageOther(100))

# Points make the game more competitive.
# This assigns a handler to add 50 points for each coin:
game.setActionFor("peasant", "collect", handler.addScore(50))

# Your turn. Assign a handler to 
# add 100 points when a robot is defeated: 
game.setActionFor("robobomb", "defeated", handler.addScore(100))
# Finally, add a goal and write directions.
# Note the survive goal can be defined for specific units:
ui.setText("directions", "Protect the peasant while they collect gems.")
ui.setText("directions", "Click on robobombs to defeat them.")
ui.setText("directions", "Each robot takes two clicks.")
ui.setText("directions", "Score 1500 points to win.")

Please state what line the error is on.

Hi, all you’ve done wrong is this:

game.setActionFor("robobomb", "defeated", handler.addScore(100))

It should be “defeat” instead of “defeated”.
That’s all.
I hope you and you’re son carry on playing!
PS, I would give the peasant higher levels of health, I used 10000 health with your code (corrected) and it works fine. Otherwise the peasant dies most of the time.
:lion: :lion: :lion:

1 Like