Help me please i can not figure this out and i only have 1000 gems what should i do???
Please post your code. According to the FAQ.
https://discourse.codecombat.com/faq
// Lure the ogres into a trap. These ogres are careful.
// They will only follow if the hero is injured.
// This function checks the hero's health
// and returns a Boolean value.
function shouldRun() {
if (hero.health < hero.maxHealth / 2) {
return true;
hero.moveXY(76, 37);
} else {
return false;
} hero.findNearestEnemy();
hero.attack(enemy);
}
while (true) {
// Move to the X only if shouldRun() returns true
hero.moveXY(75, 37);
// Else, attack!
}
Was that supposed to be there?
yes it is supposed to be there
Could you remove the comments from the code? It makes it easier for me to read your code.
Thanks!
it was there when you start should i take it out
function shouldRun() {
if (hero.health < hero.maxHealth / 2) {
return true;
hero.moveXY(76, 37);
} else {
return false;
} hero.findNearestEnemy();
hero.attack(enemy);
}
while (true) {
hero.moveXY(75, 37);
}
Make sure that you have everything lined up in the game. That may be the issue.
On line 6, I think you need if enemy;
after hero.findNearestEnemy
function shouldRun() {
if (hero.health < hero.maxHealth / 2) {
return true;
hero.moveXY(76, 37);
} else {
return false;
} hero.findNearestEnemy();
if (enemy) {
hero.attack(enemy);
}
}
while (true) {
hero.moveXY(75, 37);
}
like this?
Yes…try to run it
it says that i cant have hero.moveXY after return true
It may be a bug. Check with @Bryukh, I’m not sure about it.
It’s not a bug. Any code after return
won’t be called.
Look
if (hero.health < hero.maxHealth / 2) {
return true;
hero.moveXY(76, 37); }
Any command after return wont be called,
And you already have this code here.
while (true) {
hero.moveXY(75, 37);
}
Btw the code above is also wrong but i dont want to do everything for you. For now your main issue its useless hero.moveXY after return.
When you will remove that, you will have to use the function in the while loop
If i wasnt clear enought feel free to ask i will try to answer as best as i can.
I’ve been stuck on this level for a long time. Please tell me what is wrong with my code.
function shouldRun() {
if (hero.health < hero.maxHealth / 2) {
return true;
} else {
return false;
}
}
while (true) {
if (hero.health < hero.maxHealth / 2) {
hero.moveXY(76, 37);
}
else {
hero.attack(enemy);
}
}
This code just makes the hero attack the ogres until it dies.
Howdy and welcome to the forum!
You need to be using your function, rather than just coding it again. Something like:
function shouldRun() {
if (hero.health < hero.maxHealth / 2) {
return true;
} else {
return false;
}
}
while (true) {
if the <function> is true
do this
if the <function> is not true, then do this
do that
I would recommend throwing in a cleave, or other strong attack, if you have the weapon for it.
also…who is the enemy?