Weird Enemy Numbering

For some reason, when I use ‘for enemy in enemies’ in the Trials, the enemies are numbered and, weirdly enough, the one in the middle is numbered (0) and is the one that the Hero goes after.
This is not helpful. Period.
Mostly because this allows all the other enemies to attack the Hero, in the end, I get killed by a mere Thrower after I total the other enemies.
Also, for reasons unknown, my Hero does not pick up the mushrooms when I ask him to.
Help me, Level Help, you’re my only hope!

Hey @WeAreTheWarriors! Welcome to the discourse! This is a safe place to ask for help about levels and chat with people. Hope you feel welcome here and that you enjoy it :slight_smile:

Could you please format your code so that we can see where the error is? And maybe a screenshot of it?

3 Likes

Sure, I can show you a screenshot, but I have no idea how to do that format thingy you guys do because I am a stupid monkey. :upside_down_face:

You can learn here: How to Post Your Code With Radiant, Harmonious Formatting

1 Like

Could you tell us wha my level this is?

The level I’m working on is The Trials

Also, here is the screenshot:


I was going to add more as I went along, but I can’t even get to the first Oasis without frickin’ dying!

Instead of looping through each enemy in the “enemies” array, try using hero.findNearestEnemy(), which will always find the nearest enemy.

Whenever I do something including ‘enemy’, my hero attacks one guy and then repeats ‘but it’s dead!’ like an idiot.

You can check whether an enemy is dead or not by adding an if statement like
if enemy:

#attack or whatever you want to do

P.S. you can format your code by clicking this button:
Screenshot from 2024-01-27 17-16-14
And then pasting your code inside the quotes

While True:
   for enemy in enemies:
      hero.attack(enemy)

What does ‘triple backticks’ mean?

It’s the quotes that appean when you click the button I mentioned above:
Like these: ```

two sets of them will “format” anything in between:
code

Ah, I see.
Thank you

1 Like

Bah.
I’ve tried that now, too. The same thing happens.

  1. Attacking enemies using a for-in loop isn’t very effective, as the order of the find enemies array is random (I think).
  2. You should try attacking the nearest enemy instead.
  3. Make sure to put your variables inside the while-true loop or else they won’t update

Can you run it and show the whole screen?