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);
}
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.
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.
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);
}
}