Summit's gate help!

help would be appreciated.
my code is not working. right after I break through the door, (see picture), after it starts targeting one of the beam towers, after 3 or 4 hits, it stops attacking, and just stands there, but there is no error sign or syntax error.this is my code:
`
while (true) {
var enemy = hero.findNearestEnemy();

if (enemy) {
    hero.attack(enemy);
    hero.attack(enemy);
}
var ready = hero.isReady("hurl");
if (ready && enemy) {
    hero.hurl(enemy);
}
var ready1 = hero.isReady("stomp");
if (ready1 && enemy) {
    hero.stomp();
}
var flag = hero.findFlag("green");
if (flag) {
    hero.pickUpFlag(flag);
}

}

`

1 Like

beam towers normally have 2000 health, but after my hero attacks it once or twice, it won’t attack it anymore.
(by the way, I have the sword of forgotten, so it does a lot of damage a hit.) I expected it to target the ogres or keep attacking the beam tower.

1 Like

I think you can try to put the attack code at the bottom.

1 Like

Or try to separate each individual section into a different function so you can organize your plans bit by bit, which is more convenient.

1 Like

@jcjuly I tried it but it still doesn’t attack, this time earlier.

It stopped attacking.

1 Like

Hi there,
You can simplify your code a bit. For example, instead of:

var ready = hero.isReady("hurl");
if (ready && enemy) {
    hero.hurl(enemy);

You can do:

if (hero.isReady("hurl") and enemy) {
    hero.hurl(enemy);

But, you could organize it even better by having an enemy check at the top, then checking all the various abilities after.

if (enemy) {
    if(hero.isReady("hurl") {
        do hurl things ...
    }
    if(hero.isReady("stomp") {
        do stompy things ...
    }
}

The simpler your code is, the easier it will be for you to figure out what's going on and where something is going wrong.
1 Like

Its still not attacking when I command it to.

while (true) {
    var enemy = hero.findNearestEnemy();
    if (enemy) {
        hero.attack(enemy);
        hero.attack(enemy);
    }
if (enemy) {
    if(hero.isReady("hurl")) {
        hero.hurl(enemy);
    }
    if(hero.isReady("stomp")) {
        hero.stomp();
        
    }
}
    var flag = hero.findFlag("green");
    if (flag) {
        hero.pickUpFlag(flag);
    }
}

1 Like

No need for help. I am already done now.