[C++] Desert Combat help!

Here is the code.

Error : there are no enemy. use enemy = hero.findNearestEnemy(); = line 15

int main() {
auto ordersGiven = 0;
while (ordersGiven < 5) {
// Move down 10 meters.
hero.moveXY(hero.pos.x, hero.pos.y - 10);
// Order your ally to “Attack!” with hero.say
// They can only hear you if you are on the X.
hero.say(“Attack!”);

    // Be sure to increment ordersGiven!
    ordersGiven += 1;
}

while(true) {
    enemy = hero.findNearestEnemy();
    // When you're done giving orders, join the attack.
    hero.attack(enemy);
}

return 0;

}

1 Like

You need to check if there’s enemy.

1 Like

enemy = hero.findNearestEnemy();

1 Like

You need to check the enemy:

while(true) {
    enemy = hero.findNearestEnemy();
    if (enemy){
    // When you're done giving orders, join the attack.
    hero.attack(enemy);
   }
}
1 Like

There are a enemy ARELT - BRAWLER

1 Like

I solved it.

while(true) {

    //its missing auto
    auto enemy = hero.findNearestEnemy();

}

5 Likes

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.