Hello,
I try to find the issue in my code for 2 days now but i cant find it… it collect the coins and break after 30 secounds, go to the npc and says for example 15 instead of 19… i wirte in java.
// Fight enemies for 15 seconds.
// Keep count whenever an enemy is defeated.
var defeated = 0;
var totalGold = 0;
while (true) {
var enemy = hero.findNearestEnemy();
if (enemy) {
hero.attack(enemy);
if (enemy.health <= 0) {
defeated += 1;
}
}
if (hero.now() > 15) {
break;
}
}
// Tell Naria how many enemies you defeated.
hero.moveXY(59, 33);
hero.say(defeated);
// Collect coins until the clock reaches 30 seconds.
while(true) {
var coin = hero.findNearestItem();
if (coin) {
var x = coin.pos.x;
var y = coin.pos.y;
hero.moveXY(x, y);
totalGold += coin.value;
}
if (hero.now() > 30){
break;
}
}
// Tell Naria how much gold you collected.
hero.moveXY(59, 33);
hero.say(totalGold);
// Fight enemies until the clock reaches 45 seconds.
// Remember to reset the count of defeated enemies!
while(true) {
var enemy = hero.findNearestEnemy();
if (enemy){
hero.attack(enemy);
if (enemy.health >= 0){
defeated += 1;
}
}
if (hero.now() > 45){
break;
}
}
// Tell Naria how many enemies you defeated.
hero.moveXY(59, 33);
hero.say("defeated");