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!
Welcome to the forum @Turnerkid! 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!
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
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()
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()
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()
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()
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