Help : A precious treasure - C++

Hello, Can you explain to me why it tells me that “attackEnemy”, is not a function? However,I declared the function well, it seems to me, can you tell me my mistake? Thanks in advance

// Les péons tentent de vous voler vos pièces!
// Ecrivez une fonction pour les rembarrer avant qu'ils ne puissent vous prendre vos pièces.

auto pickUpCoin() {
    auto coin = hero.findNearestItem();
    if(coin) {
        hero.moveXY(coin.pos.x, coin.pos.y);
    }
}

int main() {
    // Ecrivez la fonction attaqueEnnemi ci-dessous.
    // Trouvez les ennemis les plus proches et attaquez-les s'ils existent!
    auto attackEnemy = hero.findNearestEnemy();
    if (attackEnemy) {
        hero.attack(attackEnemy);
    }
    
    while(true) {
        attackEnemy(); // ∆ Décommentez cette ligne après avoir écrit la fonction attaqueEnnemi.
        pickUpCoin();
    }
    return 0;
1 Like

No, you didn’t define the function

1 Like

This is not a function dude

1 Like

This is not an explanation dude.
Lol

2 Likes

This is the enemy itself, it’s not a function, to attack the enemy, you need to do hero.attack(enemyVariable) and in this case enemyVariable is attackEnemy, so instead of doing attackEnemy() you do hero.attack(attackEnemy)

3 Likes

It should be int attackEnemy() { I guess.
Correct me if I’m wrong

2 Likes

But then the code won’t work, the stuff inside int main is the program…

1 Like

Oh, okay, but then the attackEnemy() function is missing.

1 Like

Yeah, but they don’t need the function

2 Likes

They thought the variable was the function, that’s it

2 Likes

Yeah, in python:

enemy = hero.findnearestEnemy()
while True:
    enemy()

This is wrong lol🤣

That sentence doesn’t make any sense, also it’s off-topic.

1 Like

Welcome to the forum @Loctaw! :partying_face: This is a friendly place where you can ask help on levels, report bugs, or just chat with other coders! Have a great time :slight_smile:

kinda late to welcome them, don’t you think?

1 Like

Yeah, i just realize we haven’t welcome them

Thanks for your help ! I’m a beginner in programming, and I’m trying to understand, sorry if I ask questions that may be futile in your eyes. I modified my code by placing it above “int main()” when I was recommended to put it below, and it worked. Is there something to modify for entry below “int main()” or the recommendation was wrong?
And thank you for the welcome!

auto pickUpCoin() {
    auto coin = hero.findNearestItem();
    if(coin) {
        hero.moveXY(coin.pos.x, coin.pos.y);
    }
}

auto attackEnemy() {
    auto enemy = hero.findNearestEnemy();
    if (enemy) {
        hero.attack(enemy);
    }
}
int main() {
    // Ecrivez la fonction attaqueEnnemi ci-dessous.
    // Trouvez les ennemis les plus proches et attaquez-les s'ils existent!
    
    
    while(true) {
        attackEnemy(); // ∆ Décommentez cette ligne après avoir écrit la fonction attaqueEnnemi.
        pickUpCoin();
    }
    return 0;
}

You can try “run” or “submit”

What do you mean?