Help with the level Keeping Time!


#1

Ok, so this is my code,

// Use your new skill to choose what to do: hero.now()
while (true) {
    if (enemy) {
        var enemy = this.hero.findNearestEnemy();
    }
    // If it's the first 10 seconds, fight.
    if (this.now() < 10 & enemy != "palisade") {
        if (enemy) {
        this.attack(enemy);
        this.attack(enemy);    
        }
            // Else, if it's the first 30 seconds, collect coins.
    } else if (this.now() < 35) {
        if (item) {
            var item = this.hero.findNearestItem();
            this.hero.moveXY(item.pos.x, item.pos.y);
            if (gold >= 22) {
                this.hero.say("soldier");
            }
        }
        if (item) {
            var itemX = item.x;
            var itemY = item.y;
        }    // After 30 seconds, join the raid!
    } else {
        if (enemy) {
            var enemyU = this.findNearest(this.findEnemies());
            this.hero.attack(enemyU);
            this.hero.shield();
        }
    }
}

But how do I keep Nadia of the leaf from attacking the palidise if I am Anaya?


#2

You don’t. When the time is up and she starts to attack, you join in with the soldiers you have bought.


#3

Ok, but my code does nothing, even though it has no errors. :neutral_face:


#4

first of all you can’t do this
if (enemy) { var enemy = this.hero.findNearestEnemy(); }
because you can’t ask if enemy if you define it after.
Why do you say
this.hero....();
the cod is wrong