Sarven Shepherd python confusing comments

In my opinion string

if enemy.type != "sand-yak":

is in wrong position from very beginning. Or maybe it is for purpose :smile:

loop:
    enemies = self.findEnemies()
    enemyIndex = 0

    # Wrap this logic in a while loop to attack all enemies.
    
    enemy = enemies[enemyIndex]
    # "!=" means "not equal to."
    if enemy.type != "sand-yak":
        # While the enemy's health is greater than 0, attack it!
        
        pass

Iv been testing many variations with original script. None worked for me at least with simple correction. It might confuse most of the beginners.
What the rest of players think about that?
My script:

loop:
    enemies = self.findEnemies()
    enemyIndex = 0

    while enemyIndex < len(enemies):
        enemy = enemies[enemyIndex]
        enemyIndex = enemyIndex + 1
        for enemy in enemies:
            if enemy.type != "sand-yak":
                while enemy.health > 0:
                    if self.isReady("power-up"):
                        self.powerUp()
                    else:
                        self.attack(enemy)

Why do you double loop it?

while loop on enemies
– for loop on enemies

Use one or the other.

Actually, that’s the intended solution, what you posted. Can you think of a way to get the sample code to be more helpful, while letting the player practice the while loops from scratch?

Well, after he removes the extra loop it is the intended solution, unless of course you actually intend for there to be three loops

while loop on enemies
–for loop on enemies
– -- while loop on health

Remove the “for enemy in” line and back off the indent on the code following it:
(copied and edited)

    while enemyIndex < len(enemies):
        enemy = enemies[enemyIndex]
        enemyIndex = enemyIndex + 1
        if enemy.type != "sand-yak":
            while enemy.health > 0:
                if self.isReady("power-up"):
                    self.powerUp()
                else:
                    self.attack(enemy)

(really need that spoiler + code)

if it whines about an enemy not existing change the if to:

        if enemy and enemy.type != "sand-yak":
1 Like

Im real askhole. few weeks ago i didnt even knew what programming is. Hard to learn while english is not my native. I might look like complete noob and i am. To be pain in the ass is inevitable.

Excellent correction.