Hero.throw(enemy);

Hello. It seems that in C++ the hero.throw(enemy); does not work.

It keeps asking for a semicolon even though it’s there!

Kind Regards

Oliver

1 Like

Here is my Code.

// Use charges to soften up packs of ogres.
// Then pick them off with your bow.

// Use charges to soften up packs of ogres.
// Then pick them off with your bow.

int main() {
    while(true) {
        auto enemy = hero.findNearestEnemy();
        if (enemy) {
            if (hero.isReady("throw")) {
                float distance = hero.distanceTo(enemy);
                // Only throw if the ogres are more than 15m away.
                // Use "if" to compare distance to 15.
                if (distance > 15) {
                    hero.throw(enemy);  // here the error shows up about the missing semicolon
                }
                // Use "else" to attack if you're not throwing.
                else {
                    hero.attack(enemy);
                }
            }
            else {
                hero.attack(enemy);
            }
        }
    }
    return 0;
}

1 Like

Welcome the CoCo DIscourse forums @Snake2109 ! :partying_face:
This is a place to get help within levels, dicuss ideas, give suggestions for the game or just chat with other awesome coders!
Check out the FAQ and the rules if you haven’t already and have fun! :grinning_face_with_smiling_eyes:

Welcome to the forum @Snake2109.

Hmmm. You are right, this does look like it should work. Sometimes reloading the level will work, unfortunately you might have to reset the level, too. I am not exactly an expert on C++ so i could be wrong.

Save your code to a text file, reset the level, and then try again.

1 Like

Hi and thank you for the kind welcome! :grinning:

I tried as you suggested but the problem is still persists.
on an other note, I was able to reproduce the bug in another level “Swift Dagger”.

The missions can be completed using different attack style but i guess it’ll not be possible to use the hero.throw(); in other missions as well… or do you or someone else knows if it’s working in the multiplayer battles?

// Use your bow at long range and dagger at short range.

int main() {
    while(true) {
        auto enemy = hero.findNearestEnemy();
        if (enemy) {
            float distance = hero.distanceTo(enemy);
            if (distance < hero.throwRange) {
                hero.throw(enemy);
            }
            else {
                // Attack the enemy with your bow.
                hero.attack(enemy);
                
            }
        }
    }
    return 0;
}

following i have posted a screenshot of the error message.

#UPD.

I posted the Bug to GitHub!

Sorry only now read the post, asking us to post to GitHub!

If anyone is interested here’s the link.

Blockquote
hero.throw() not usable in C++ · Issue #6517 · codecombat/codecombat · GitHub

Thanks @ the team of codecombat for making a great learning tool! :smiley: