Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Alpine rally- please help

I got problem, after Ogres pass my hero stops and yeti kill him :(```
while (true) {
hero.moveXY(hero.pos.x + 1, hero.pos.y);
if (hero.canCast(“invisibility”)) {
hero.cast(“invisibility”, hero);
}
if (hero.canCast(“haste”)) {
hero.cast(“haste”, hero);
}
var enemies = hero.findEnemies();
var enemyIndex = 0;
while (enemyIndex < enemies.length) {
var enemy = enemies[enemyIndex];
if (enemy.type == “scout” && hero.distanceTo(enemy) < 8) {
hero.manaBlast();
if (hero.isReady(“haste”)) {
hero.cast(“haste”, hero);
}
if (hero.isReady(“reset-cooldown”)) {
hero.resetCooldown(“haste”);
}
enemyIndex++;
}
}

while (true) {
  hero.moveXY(hero.pos.x + 1, hero.pos.y);
    if (hero.canCast("invisibility")) {
        hero.cast("invisibility", hero);
    }
    if (hero.canCast("haste")) {
        hero.cast("haste", hero);
    }
    var enemies = hero.findEnemies();
    var enemyIndex = 0;
    while (enemyIndex < enemies.length) {
        var enemy = enemies[enemyIndex];
        if (enemy.type == "scout" && hero.distanceTo(enemy) < 8) {
            hero.manaBlast();
            if (hero.isReady("haste")) {
                hero.cast("haste", hero);
            }
            if (hero.isReady("reset-cooldown")) {
                hero.resetCooldown("haste");
            }    // if (hero.isReady("reset-cooldown")) {
                 //     hero.resetCooldown("haste");    //  hero.resetCooldown("reset-cooldown");  
        }
        enemyIndex++;
    }
}

if (hero.isReady(“reset-cooldown”)) {
hero.resetCooldown(“haste”);

doesnt work :frowning:

Try doing it based on time instead…4 seconds aught to do it.

I dont understand :frowning:

Hi Zambi25,

I’ve just (finally) got this level completed, but it seems to be a hard one.
I’m not sure why my final code worked, but a few things I found:

  • I needed to put in 3 separate while loops. I don’t really understand why, but they made the hero go faster (maybe it cuts down the computer processing time?). I set the loops to be ‘while the hero’s x position is less than…’ so that they completed and moved on to the next one.

  • Discourse had suggestions from people saying to either create a soldier as a decoy, or get more equipment for a better health score. My code means that one or the other is needed (better code means you might do without either).

  • resetCooldown is a property that Pender Spellbane has (not any of the kit). It took me a while to work this out.

  • The hints say to use haste or shrink. I had to buy a different book to use shrink, and you can only hold the book that lets you use shrink or the book that lets you use haste. Ie you can’t use both spells in the same attempt. So buying the book didn’t help me at all (hopefully it’ll be useful in the future).

  • Casting invisibility didn’t help me at all - it just made my hero stop running until the spell had ran out, and then I got caught. Other people seemed to use it, so I don’t know what I was doing wrong!

  • Using hero.move seemed to be better than using hero.moveXY. It means my hero can run and think at the same time (maybe).

Good luck with cracking it. I’ve made half a dozen attempts, given up and then come back again before I’ve got it. And don’t be afraid to experiment!

hi , thx for response but I still cant pass this level

Could you post your current code? I’m guessing it’s changed since you last put it up.