The Trials: Trouble Breaking Loop


#1

Hi, I am starting The Trials, and I am stuck at the end of the first Oasis. I kill all the enemies, eat all the mushrooms and defeat the onslaught including an enormous ogre. My problem is figuring how to wait for the final attacks. I set up a loop to watch for enemies and invoke an array if enemies appear, but I don’t know how to break the loop when the enemies stop appearing.

#attack Enemies is obviously an infinite if I can’t figure out how to break it.

I know that I can use flags to solve this problem, but I was hoping for a logic based solution.

Thanks for your help.

#Gather mushrooms
shrooms = self.findItems()
itemIndex = 0
while itemIndex < len(shrooms):
nShroom = shrooms[itemIndex]
self.moveXY(nShroom.pos.x, nShroom.pos.y)
itemIndex += 1

#attack Enemies
loop:
enemies = self.findEnemies()
enemyIndex = 0
while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
while enemy.health > 0:
self.attack(enemy)
enemyIndex +=1


#2

Please format your code correctly by highlighting it and clicking the </> button. Thanks!

When I did the level, I found that the Oasis Guardian (the huge ogre) showed up very near the end, so I broke the loop after defeating it, then checking for enemies once or twice more.


#3

The loop at the start of your code for attacking enemy is unnecessary as you already have a while-loop. I think it will work if you remove it as it will stop looping once there is no more enemies.


#4

But the enemies don’t all come at once. After he gets a new set of enemies, what will happen?


#5

Oops. Sorry for responding so late. But if you have a loop at the start of the entire thing, the while loop will break once there is no more enemy. So when a new enemy appears, the hero will find the enemy again and the while loop will continue


#6

At some point, though, you have to move on to the next mushroom field.