I need some assistance on the Level: Village Champion

I need some help on the Level as I believe there is a flaw (or more) in my code. I tried getting help from the other Discourses related to this level but it is still not working. Can someone please give me some assistance? Thanks in advance!

(Code will be provided if asked.)

Welcome to the forum @Turnerkid! :partying_face: This is a friendly place where you can ask help on levels, report bugs, or just chat with other coders! Don’t forget to read the guidelines if you haven’t yet. Have a great time!

Yes please provide it (dont forget to format it :slight_smile: )

1 Like

Hi @TurnerKid! Welcome here to the discourse! Here, people talk about problems, off-topic stuff and all of that! And if you need help, you can ask for help. And if you want to format, just click the format button that looks like </>.

[EDIT] Or some other people like @PeterPalov or @Watamelon
[EDIT 2] Removed things; thanks moonwatcher348

1 Like

You should probably not @ chaboi or nick in welcome posts

I also will help only when I see the code and the problem in it.

Hi sorry for the long wait. Been busy.

Here is the 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 ogre = hero.findNearestEnemy();
if (ogre) {
if (hero.isReady(“cleave”)) {
hero.cleave(ogre);
hero.say(orge)
}
// Else attack the ogre:
else {

    hero.attack(orge);
     hero.say(orge);
    }
}

}

// 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()

}

Why do you say it? I don’t think you need this part (and the part in else). The rest of the code seems fine

1 Like

Oh. I see. I’ll make the change.

Okay so I changed the ogre to enemy. but the hero is doing nothing.

Here’s my new code:

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);
hero.say(enemy)
}
// Else attack the ogre:
else {

    hero.attack(enemy);
     hero.say(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()

}

No, remove this line. You shouldn’t say anything.

Okay. Jeez that reply was fast.

Removed that line. Hero is still not doing anything.
New code:

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()

}

Everywhere you summon the function, it should be cleaveOrAttack(), not cleaveorAttack(). Capital letters/no typos are really important in coding.

Change is made, but hero’s is still not moving.
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.

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()

}

Could you send a screenshot?

I found the problem, you should close the function using } right before this statement

Then you put everything below in a while true loop

Oh, I just noticed, this should be in a loop (While True). Else your hero will move there one time and then do nothing
Edit: Sorry, that’s literally what Aya said above :joy:

call*

And you should probably wrap your whole code in the code format otherwise it’s difficult to read :upside_down_face:

Stop correcting me. I know what I say.
And I don’t think formatting is needed now, because jthe problem is almost solved, but for future, yes.