Ogre Gorge Gouger Keeps Giving Me the Infinite Loop Error


#1

I’m pretty sure this isn’t an infinite loop. It will stop when the timer hits 20.

while self.now() < 20:
    coins = self.findItems()
    for coin in coins:
        if coin.value > 1 and self.now() < 20:
            self.moveXY(coin.pos.x,coin.pos.y)

#2

I wonder if possibly - when you only have coins of value 1 then the loop will effectively do nothing, and I think this then runs really fast, and will run you over the loop counter. You can try collecting all the coins >= 1, or maybe doing a say or some other command?
And on further thought - if there are no coins it may end up in the same situation.


#3

Yes, matt hit the nail in on this one, pounded it all the way in with one blow. :smile:

Doing nothing really really fast will get marked by the system as “slow/inf-loop” code.
It takes very little real time for the system to cry foul on such tight loops.
The only thing in your code to cause it to “yield” (“play nice” and let the rest of the system get code in edgewise) is the moveXY and that only happens when you have coins greater than 1 in value.

loop:
    coins = self.findItems()
    for coin in coins:
        if coin.value > 1 and self.now() < 20:
            self.moveXY(coin.pos.x,coin.pos.y)
    if self.now() >= 20:
        break

should fix the slow/inf-loop, as the coco-loop command plays nice (yields).