[SOLVED] I cant get the level Sarven Shepherd

did you try to clear the cache or whatever its called?

i have ofitialy broken my computer

nah just try to clear the cache dude.

nothing is working i hate my life

maby it will work tomorrow?..

hopfully

nah try to do what chaboi said

but right now i am taking a brake

alright then bye
P.S its break not brake. you dont have wheels :grin:

and how do i clear my cache

read this

sorry break not brake

I was just kidding about the break stuff :grin:

ok bye
see you later maby

alright bye :grin:
remember to do what i said for the code since i did succeed with your code

I know it looks like you’ve got this kind of cleared up, but I just want to clarify the issue.
The reason there was an infinite loop is because your code does actually create an inifinite loop.

The while loop will continue to run while enemIndex is less than the amount of enemies.
But look at where you are incrementing (adding one to) enemyIndex.

You are only increasing enemyIndex if the enemy is not a sand yak (!= “sand-yak”). What about when the enemy is a sand yak? That if statement will never run will it? Meaning enemyIndex will never increase, meaning that the while enemyIndex < len(enemies) will always be true because enemyIndex won’t increase for some of the enemies. It will always be less than len(enemies). This is the cause of the infinite loop. It’s looping for ever.
As Falcons said, press the comment out my code button. It may ask you again, and if so, press it again. Then it should work. Also try clearing browser history and cache etc.
When the level opens, you can then put the enemyIndex in the right place, so it runs whether or not the enemy != “sand-yak”. You don’t want it inside that if statement.
I hope that helps you understand the cause of the issue.
Danny

3 Likes

my hero just wont move and i saw the other guy do the level with my code but I cant do it

# Use while loops to pick out the ogre

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!
            hero.attack(enemies)
            enemyIndex +=1
            pass
        
    hero.moveXY(40, 32)
    

how do I get rid of the infinite loop

and i keep getting the infinate loop thing

this should be

this

        if enemy.type != "sand-yak":
            # While the enemy's health is greater than 0, attack it!
            hero.attack(enemies)
            
            pass
        enemyIndex +=1 

It should be something like that