Operation Killdeer javascript please help


#1

Help me please i can not figure this out and i only have 1000 gems what should i do???


#2

Please post your code. According to the FAQ.


#3
// 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!
    
}


#4

Was that supposed to be there?


#5

yes it is supposed to be there


#6

Could you remove the comments from the code? It makes it easier for me to read your code.

Thanks!


#7

it was there when you start should i take it out


#8
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);

    
}


#9

Make sure that you have everything lined up in the game. That may be the issue.


#10

On line 6, I think you need if enemy; after hero.findNearestEnemy


#11
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?


#12

Yes…try to run it


#13

it says that i cant have hero.moveXY after return true


#14

It may be a bug. Check with @Bryukh, I’m not sure about it.


#15

It’s not a bug. Any code after return won’t be called.


#16

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.