Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Infinite Loop on Slalom


Hello here is my code that keep becoming an infinite loop. idk what the problem it. It might just be to early in the morning for me. lol

> gems = self.findItems()

> loop:
>     start = self.pos.x
>     while self.pos.x < self.pos.x + 5 and self.pos.x < 60:
>         self.move({'x': start + 5, 'y': 35})
>         finish = self.pos.x
>     while self.pos.x < finsih + 5 and self.pos.x < 60:
>         gem = gems[0]
>         self.move(gem.pos)
>         gem = gems[len(gems) + 1]
>         finish = slef.pos.x
>     start = finsih



I am having the same problem. All of a sudden code which was working now has “slow/inf-loop”.

edit: hahahaha
so I used bad example code. But what ever was the problem before seem gone now.


With the first while loop, would it ever finish? In that self.pos.x will always be less that self.pos.x + 5.


(OK, now that my slow/inf-loop problem is gone (no idea) I can look at yours…)

typoes, such as “finsih” instead of “finish” and “slef” instead of “self”

The “and” clauses of the while’s are probably trying to do the job of the “loop:” so get rid of them. Once that is done, you will see matt’s point. I think this is just because you used “self.pos.x” when you meant “start”, since the code is set up like start should be there infront of the “+ 5”.

“gem = gems[0]” and “gem = gems[len(gems) + 1]” can’t be right since the first will always be #0 and the second will always try to use the gem after the last gem in the list…(which doesn’t exist)

remove the second gem = gems and keep track of which gem you are getting…


(dang computer just shut itself down Instant-off.)

Please don’t hand type in your code, copy and paste your code from the code window.

You have typos (don’t know if they are in your actual code or not) (finsih & slef)

Remove the "and self.pos.x < 60"s those are trying to do the "loop:"s job.
As matt says you have a self.pos.x < self.pos.x + 5, looks like you meant “start + 5”

gem = gems[0] will always me gems[0]
gem = gems[len(gems) + 1] will never work “len(gems)” is already a non-existant gem “+ 1” is still non-existant.
(if you meant “- 1” then it would always be the last gem, which doesn’t get you any farther than the other always being first. Especially, since the next thing to happen would be to set it to the first… (gem = last, while check, gem = first, use gem, gem = last, …)

the second one needs to just be removed and the first should set gem to the current gem.

So except for the “gems” bit we just went over, you have a good idea you just have several lines with the wrong indent and some are in the wrong place.

example of place & indent. the setting of “gem” to current gem should be somewhere (outside of while loops) between loop: and the second while loop. it doesn’t get/need reset during the walking… (same with start&finish)

Only put in the loop, what needs to be - in the loop.

OK, having said all that . . . we can get to the real problem . . . “move()” likes to cause the “slow/inf-loop” error. It is not your code. (I know nick is/was looking into it.)

spoiler: code would work if not for Mr. move()
gems = self.findItems()
count = 0

    gem = gems[count]
    count +=1

    start = self.pos.x
    while self.pos.x < start + 5:
        self.move({'x': start + 5, 'y': 35})

    finish = self.pos.x
    while self.pos.x < finish + 5:



Thanks. I fixed all the spelling errors and got rid of the non-existent statements. As well as simplified the code. Like I said in the first post it was too early for me to be doing anything.

The code runs but it still says that there is an error with my code but it involves the move() command. As you mentioned before that

“move()” likes to cause the “slow/inf-loop”


@nmsiriban0114 Just make sure the gem exists before you go to get it. Change:



        if gem: