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

Bookkeeper (Help Me)

Hey guys I’m in a hurry here I have more things to do so i’m just gonna post the code here.

// This function allows to fight until the certain time
// and report about defeated enemies.
function fightAndReport(untilTime) {
    var defeated = 0;
    while (true) {
        var enemy = hero.findNearestEnemy();
        if (enemy) {
            hero.attack(enemy);
            if (enemy.health <= 0) {
                defeated += 1;
            }
        }
        if (hero.time > untilTime) {
            break;
        }
    }
    hero.moveXY(59, 33);
    hero.say(defeated);
}

// Fight 15 seconds and tell Naria how many enemies you defeated.
fightAndReport(15);

// Collect coins until the clock reaches 30 seconds.
var item = hero.findNearestItem();

if (hero.time > 30) {
    hero.moveXY(item.pos.x,item.pos.y);
}

// Tell Naria how much gold you collected.
hero.say(hero.gold);

// Fight enemies until the clock reaches 45 seconds.
fightAndReport(45);

Instead of if put while

This put inside the while loop under it

Does it work now? :face_with_raised_eyebrow:

Before this put one of these

Thanks @AnSeDra ! It worked