Sarven Shepherd(python)

my hero never moves. I’ve tried putting the code in, and out of the while true loop. I’ve tried moving the “enemyIndex += 1” around. please help

while True:
    enemies = hero.findEnemies()
    enemyIndex = 0
    # Wrap this logic in a while loop to attack all enemies.
    # Find the array's length with:  len(enemies)
    while enemyIndex < len(enemies):
        enemy = enemies[enemyIndex]
        # "!=" means "not equal to."
        if enemy.type != "sand-yak":
            # While the enemy's health is greater than 0, attack it!
            while > 0:
            enemyIndex += 1

# Between waves, move back to the center.
hero.moveXY(40, 32)

For this level it wants you to pretty much create an over-complicated loop where you want to attack enemies. For this I actually just created a basic loop like this:

while True:
    enemy = hero.findNearestEnemy()
    enemyIndex = 0
    if enemy.type != "sand-yak":

You should try this out and see if it works for you.


Thanks, that was way easier. My whole code:

while True:
    enemy = hero.findNearestEnemy()
    if enemy.type != "sand-yak":

My hero was slow to react to the enemy though.It was wierd. :thinking: :thinking:

move the hero.moveXY(40, 32) into the while enemyIndex < len(enemies): loop and add enemyIndex = enemyIndex + 1 below the hero.moveXY

I just don’t get these loops. I’m already stuck on the next level. :anguished: :anguished: :sob:

which one is it i can help you

The level is Shine Getter. Should I make a new topic?


Or if you want to just explain the loops, you can send message.

yeah i didn’t know you finished the levels

huh? what do you mean?

never mind…

Sooo… I’ll just make new topic.

yup pretty much(20chars)

The link: Shine Getter(python)

i know i’m trying to figure out what’s wrong with yr code

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