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

[SOLVED] Help for Lurkers code please

I’m on the Lurkers level, and I can’t figure out whats wrong!

return

enemyIndex = 0
enemies = hero.findEnemies()

while enemyIndex < 6:
    enemy = enemies(enemyIndex)
    if enemy.type == "shaman":
        pos = enemy.pos
        x = pos.x
        y = pos.y
        hero.moveXY(x, y)
        hero.say ("Wake up!")
        enemyIndex += 1
        while enemy.health > 0:
            hero.attack(enemy)
    else:
        enemyIndex += 1

Can anybody help?

Hi,
The problem is on this line:

enemy = enemies(enemyIndex)

When you put something (in this case “enemies”) in front of () the computer thinks “enemies” is a function. It should be an array.
What type of brackets do you use to access parts of an array? (You can look in earlier levels if you don’t know it know.)
I hope this helps,
Danny

1 Like

This better?

enemy = enemies[enemyIndex]
1 Like

Sadly, the result was still the hero not moving from his spot. (Sorry I didn’t mention this earlier)

Have you gotten rid of the return?

Just did, but its running now and not doing anything :confused:

Do you really need the moveXY and hero.say statements? By attacking, the hero will automatically move towards the target…saying something is cute, but kinda pointless.This is more of a cosmetic clean-up, not a solution.

However, you increment your counter twice. Instead, try making it the final statement of your outer while loop.

1 Like

Might there be a bug with the level? I just tried, and the level just kept running the code for ages. Also, whenever I try to get onto the level when the page reloads it shows up an error and when I run the code ,when I eventually get Lurkers up, my code seems stuck on

enemies = hero.findEnemies()

for some reason, for what feels like hours.

Well, I doubt it’s a bug…my code succeeds properly; if a bug, then it should fail too. I modified your code as suggested above and it passed too. (I tried with and without the move and say statements…both passed.)

It appears to be the else clause that is causing the problem.

Also, likely, it is pausing there as the last statement completed…it’s having a problem with the next ‘block’ or line of code.

1 Like

I would change these things, but I can’t get onto the level to change them for some reason. If the page reloads, or I reload it because I want to, then it opens up fine for “Anonymous Player” but not for me at all.

Would an Apple device slow down code?

@dedreous and @Deadpool198 thanks for all the help! I reset the code and it worked much better. I have now completed the level.