Bash 'em all. Please Help

while(true) {
  var enemies = hero.findEnemies();
  var enemyIndex = 0;
while(enemyIndex < enemies.length) {
    var enemy = enemies[enemyIndex];
    hero.bash(enemy);
    hero.moveXY(40, 33);
    enemyIndex ++;
 }
}

The thing is that when hero bashes enemy[0], it can’t reach bombs so enemy[0] stays alive, but when hero bashes enemy[1,2,3] it works for them.
So may be there is a bug or something. Can you please help me with that. Thank you.

if (hero.isReady(‘bash’) && hero.isPathClear(hero.pos, enemy.pos))
Before hero.bash(enemy) it’s much safer to check if bash is ready and if path to the enemy is clear. After blowing all fire traps it’s easy to collect the gold.

Doesn’t work for me.
03

see your glasses
image

I still have the same problem - when hero bashes enemy[0], it can’t reach bombs so enemy[0] stays alive, but when hero bashes enemy[1,2,3] it works for them.

while (true) {
    var enemies = hero.findEnemies();
    var enemyIndex = 0;
    while (enemyIndex < enemies.length) {
        var enemy = enemies[enemyIndex];
        if (hero.isReady('bash') && hero.isPathClear(hero.pos, enemy.pos))
            hero.bash(enemy);
        hero.moveXY(40, 33);
        enemyIndex++;
    }
}

only this code work Ok

Man. It does not.
Same troubles.
Try it for your self. Just paiste the code.
https://codecombat.com/play/level/bash-em-all?

while (true) {
    var enemies = hero.findEnemies();
    var enemyIndex = 0;
    while (enemyIndex < enemies.length) {
        var enemy = enemies[enemyIndex];
        if (hero.isReady('bash') && hero.isPathClear(hero.pos, enemy.pos)) 
            hero.bash(enemy);
            hero.moveXY(40, 33);
        enemyIndex++;
  }
  
      var items = hero.findItems();
       var itemIndex = 0;
       while(itemIndex < items.length) {
        var gem = items[itemIndex];
        if(hero.isPathClear(hero.pos, gem.pos)) 
         hero.moveXY(gem.pos.x, gem.pos.y);
       itemIndex ++;
  }
 
}

So here is my code
It works for your hero Ida
But it doesn’t for my Ida, she just stops in the middle.

i’m depressed :slightly_frowning_face:

If you want a help tailored to your hero try this:
1 - open https://codecombat.com/play/level/bash-em-all
2 - run image
3 - with Chrome browser Ctrl+Shift+I or


4 - Developer Tools will open

5 - Seacrch for the string
|Thor's Archer| Generated random seed -1099223392 of type submissionCount from sessionIDs 5aa16b726353c7002936fb54 submissionCount 2
6 - Copy the number of your sessionIDs - it is like 5aa16b726353c7002936fb54
7. after https://codecombat.com/play/level/bash-em-all put
?session=5aa16b726353c7002936fb54 to have link https://codecombat.com/play/level/bash-em-all?session=5aa16b726353c7002936fb54 as a whole
8 - post it to get help

as a side note: I tried your code and it runs flawlessly with my hero

This worked for me. My hero was Hattori on this level.

Mod edit: please don’t post complete solutions, thanks.

HI @dylancrocker, welcome to the CodeCombat Discourse :tada:
Thank you for helping, but please could you not post complete solutions as it’s against the purpose of the Discourse and we would prefer for solutions to not be readily available to students who might use them without actually trying to solve the level.
Thanks
Danny

Oops! Won’t do it again. Thanks!

It’s absolutely fine; sorry for kind of springing on you straight away :grin:.