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

Bonemender - can't get the hero to attack

Hi, I’m not sure why my hero is not attacking. I tried copying the solutions from other entries on Bonemander but nothing seems to have worked. Can anyone help me with this?

// Heal allied soldiers to survive the siege.
while (true) {
    if (hero.canCast("regen")) {
        var bernardDistance = hero.distanceTo("Bernard");
        if (bernardDistance < 10) {
            // "Bernard" needs regeneration!
            hero.cast("regen", "Bernard");
        // Use "if" and "distanceTo" to regenerate "Chandra"
        // if she is closer than 10 meters away.
        if (hero.canCast("regen")) {
            var chandraDistance = hero.distanceTo("Chandra");
            if (chandraDistance < 10) {
                hero.cast("regen", "Chandra");
        } else {
            // If you aren't casting "regen", use "if" and "distanceTo"
            // to attack enemies that are closer than hero.attackRange.
            var enemy = hero.findNearestEnemy();
            if (enemy) {
                var enemyDistance = hero.distanceTo(enemy);
                if (enemyDistance < 30) {

Hi @David_De_Mooly and welcome to the discourse :partying_face: This is a friendly place where you can ask for help on levels, report bugs, and talk with other coders. Hope you enjoy your time here.

As for your code, I believe the apostrophe here has created a string, which is making everything after it a string, so try removing it, hopefully that works.

Hi Aya!
Thanks for your warm welcome! I’m afraid removing the comment with “aren’t” hasn’t changed anything. The code is still not working

Hmm, your code works for me. Do you definitely have a weapon equipped? If you do, please could you post a picture of your inventory because this seems to be an equipment problem.

Perhaps a bug then? I definitely have a wand just like in the screen shots attached. Where do I report it?

Screenshot 2021-09-13 at 17.47.34

Maybe this is the problem then.
Because you have quite a weak wand, it’s range is limited. Less than 30 metres it seems. This means that instead of checking whether enemyDistance is less than 30, you need to check if it’s less than hero.attackRange, as the comment says.

I tried both methods. Didn’t work. But the range is, in fact, 30
Screenshot 2021-09-13 at 18.54.17|690x384

I found the problem. The code was never able to run “else” because the first “if” was closed at the end rather than earlier

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