Stuck on codecombat level 6 game dev 2

# The player only needs to defeat some of the enemies.
game.spawnPlayerXY("guardian", 62, 25);

# Use game.addDefeatGoal(X) to allow the player to win
# after defeating X enemies! (In this case, X should be 4)
x = 4
unit = "gaurdian"
game.addDefeatGoal("guardian", "spawn", x)
enemy = unit.findNearestEnemy

while True:
    unit.attack(enemy)

I dont know what im doing wrong exactly can someone try this in their codecombat and see if it works?

// Use game.addDefeatGoal(X) to allow the player to win
// after defeating X enemies! (In this case, X should be 4)
game.addDefeatGoal(4);

You are only adding the goal, also you click on enemy when playing to attack them.

so what is the final answer?# The player only needs to defeat some of the enemies.
game.spawnPlayerXY(“guardian”, 62, 25);

Use game.addDefeatGoal(X) to allow the player to win

after defeating X enemies! (In this case, X should be 4)

x = 4
unit = “gaurdian”
game.addDefeatGoal(“guardian”, “spawn”, x)
enemy = unit.findNearestEnemy

while True:
unit.attack(enemy)

Here it says unit has no attack mathod.

Is that how you actually have it indented? And can you please format your code using </>?

Check your spelling of guardian. unit = "gaurdian"

instead of “x = 4
unit = “gaurdian”
game.addDefeatGoal(“guardian”, “spawn”, x)
enemy = unit.findNearestEnemy”
while True:
unit.attack(enemy)", use “game.addDefeatGoal(4);”.
Hopefully this works! :>

Hello and welcome to the discourse @mykhullr.17!:tada:
Please don’t revive dead topics as most of the people in this topic aren’t active and this is already solved

1 Like

If you have a problem/bug, please open a new topic.