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?


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:

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:

Ah, I see.
Thank you

1 Like

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?

New update! I’ve been saving up for an obsidian helmet because the same darn thrower keeps killing me in one shot at the end of my code and so I upgraded my armour. Now my health is higher but I still cannot attack the thrower, instead I stand there. I notice that the thrower and a comrade behind her are not numbered as enemies.
My code remains the same because it should help me through the first trial, and yet I don’t know why I can’t kill this one thrower and her boyfriend. I could really use some advice.

# This level is intended to be for advanced players. The solution should be pretty complex with a lot of moving parts. It might also be a bit of a gear check unless you use creative methods.
# You need to make your way to the first trial (Oasis of Marr) defeating enemies along the way. When you reach it, pick all the mushrooms to trigger the trial to begin. If you survive the onslaught, make your way to the next Oasis for the second trial, then the Temple. When all trials are complete you will have to face the final boss. Good luck!
# HINT: Glasses with a high visual range help tremendously on this level so buy the best you can get.
# HINT: the unit 'type' for the oasis guardians is 'oasis-guardian'
enemy = hero.findEnemies()
enemies = hero.findEnemies()
while True:
    for enemy in enemies:

One more thing: No matter what, whenever I finish other levels to get more diamonds, the arrow keeps pointing to the Trials even though I know I’m not advanced enough for its complexity.

The problem is because in the trials enemies start spawning. And since new enemies come up they aren’t in the findEnemies array. So put the enemies variable inside the while true loop. Also the enemy variable is not necessary.

Okay, that worked, thanks. Lemme see about the rest of the challenge