I need some assistance on the Level: Village Champion

“summon” isn’t the right word :]

yes. also, you said “jthe”

Okay here’s my new code:
// Incoming munchkins! Defend the town!

// Define your own function to fight the enemy!
function cleaveOrAttack() {
// In the function, find an enemy, then cleave or attack it.
var enemy = hero.findNearestEnemy();
if (enemy) {
if (hero.isReady(“cleave”)) {
hero.cleave(enemy);

    }
    // Else attack the ogre:
 else {
    
     
     
    hero.attack(enemy);

    
}

// Move between patrol points and call the function.
while(true) {

hero.moveXY(35, 34);
// Use cleaveOrAttack function you defined above.
   cleaveOrAttack()
hero.moveXY(47, 27);
// Call the function again.
   cleaveOrAttack()
hero.moveXY(60, 31);
// Call the function again.
   cleaveOrAttack();

}
}
}
Hero is still not moving. Did I do something wrong?

Hold on. I misread you message.

Okay here’s my new code. But it says there is something wrong. But there’s in nothing on the line it’s saying it’s wrong. I think It’s a bug so I’m going to create a new topic about this.

// Incoming munchkins! Defend the town!

while(true) {

// Define your own function to fight the enemy!
function cleaveOrAttack() {

// In the function, find an enemy, then cleave or attack it.
var enemy = hero.findNearestEnemy();
if (enemy) {
    if (hero.isReady("cleave")) {
        hero.cleave(enemy);
     
    }
    // Else attack the ogre:
 else {
    hero.attack(enemy);
    

 }

}
// Move between patrol points and call the function.

hero.moveXY(35, 34);
// Use cleaveOrAttack function you defined above.
   cleaveOrAttack()
hero.moveXY(47, 27);
// Call the function again.
   cleaveOrAttack()
hero.moveXY(60, 31);
// Call the function again.
   cleaveOrAttack();

}
}
}

The function should be outside the while true loop like this:

function cleaveOrAttack() {
    // your code here checking for an enemy and cleaving or attacking
}

while (true) {
    // the rest of your code here of calling the function and moving to the points

}

3 Likes

Finally Done.

Thank you all who assisted me.

1 Like

Good job. Dont forget to mark the post that helped you most as a solution so that the topic closes.

And i recommend that you remove the code that you posted at the end because it counts as a solution and people might steal it.

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.