I need help with Slalom (Python)

Here is the code im using:

[code]gems = self.findItems()

while self.pos.x < 20:
self.move({‘x’: 20, ‘y’: 35})

while self.pos.x < 25:
gem0 = gems[0]

while self.pos.x < 30:
self.move({‘x’: 30, ‘y’: 35})

while self.pos.x < 35:
gem1 = gems[1]

while self.pos.x < 40:
self.move({‘x’: 40 , ‘y’:35 })

while self.pos.x < 45:
gem2 = gems[2]

while self.pos.x < 50:
self.move({‘x’:50 , ‘y’:35})

while self.pos.x < 55:
gem3 = gems[3]

I honestly dont know what im doing wrong, help please (new to this)

If you execute that code, what does your hero do? What do you think he should do instead?

He collects one of the gems and then he just stops moving.

Your code doesn’t give a new move command after gem3 has been picked up.

But it wont even get to gem3. The code stops working “while self.pos.x < 35:” My hero just stays on the X.

Does it give you an “unexpected indent” error 'cause it seems like it should.

make all your indents the same, ESPECIALLY, in the same area of code).

while self.pos.x < 35:
    gem1 = gems[1]

(if you look at the code you posted, they aren’t lined up)

Otherwise, you must not be getting to “35.000000001” so you never leave that loop. You could try “< 34”.

My code appears to be lined up :confused: … this is the error its giving me.

Also, when I click the “help” button, the pop up window stays blank, so i’m not sure if its a glitch.(@nick) edit: i finally passed but probably not the right way. Here is a look at my code if anybody needed help. Not the most efficient but it works.

gems = self.findItems()
while self.pos.x < 20:
	self.move({'x': 20, 'y': 35})

while self.pos.x < 25:
	gem0 = gems[0]

while self.pos.x < 30:
    self.move({'x': 30, 'y': 35})
self.buildXY("fence", 35, 19)
self.buildXY("fence", 40, 41)
self.buildXY("fence", 45, 19)
self.buildXY("fence", 50, 41)
self.buildXY("fence", 56, 22)

Looks like we haven’t written a guide yet for that level, which is why it’s blank; hope to get that filled in soon.

I wasn’t easily able to reproduce the infinite loop problem, but what happens if you change your x thresholds lower and lower, like 34, 33, 32 instead of 35–does it eventually get you there?

Umm…nope, that did not seem to work either :confused: He still just stays on the 2nd red “X” and gives me the same error.

When I use the code you provided, I don’t get “hard limit”, I get the slow-infinite code error.

If I close and reopen the level, I get stuck in different places, sometimes I can get passed the 2nd redX sometimes I don’t even make it to the first gem…???..

Personally, I am inclined to blame the “move” command since it is not blocking, the code runs ahead.

Quasi-side note: We need to change the default code . . . as we are teaching a bad thing…
Honestly, I should have complained about this ages ago, but I didn’t care back then…

while x<35:
    gem1 = gems[1]
    move to gem1

Why are we teaching people to set gem# (which won’t change) inside the while loop??

Move these outside the while-loops and I stop getting the error. (yes, it is pseudo code)

gem1 = gems[1]
while x<35:
    move to gem1

If the “slow/inf code error” is codecount-time based then it makes sense, since it removes lines of code from the count and would also effect “hard limit”.

Did something change? 'cause it shouldn’t hit either limit with the expected solution…

that is the same error that i get to.

  1. Moving the gem assignment outside the while loop makes the code more efficient, but it is not the main error cause
while x<35
      move to gem1

If you set gem1 to the wrong value (if gem1.x < 35) then your hero will never move past x=35 and your code will loop forever (or until hard execution limit is reached :))

I solved by building fences


@buildXY “fire-trap”, 20, 39
@buildXY “fire-trap”, 25, 21
@buildXY “fire-trap”, 30, 35
@buildXY “fire-trap”, 40, 23
@buildXY “fire-trap”, 40, 35
@buildXY “fire-trap”, 50, 24
@buildXY “fire-trap”, 53, 37
@buildXY “fire-trap”, 57, 20


Hi Navtej_pathipati,

It’s nice that you’re trying to help these people, but they were posting about this topic 5 years ago. Please could you check the date on a topic, and only reply to recent posts.



I agree with Jenny, and could you remove the correct code so others won’t try and cheat? This is a learning forum, not a place to look for answers.

Hi Ryan, I’m sorry but we can’t post sulotions on the forum cna you please delete your post?