I need help with Slalom (Python)


#1

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]
self.move(gem0.pos)

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

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

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

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

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

while self.pos.x < 55:
gem3 = gems[3]
self.move(gem3.pos)[/code]

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


#2

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


#3

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


#4

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


#5

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


#6

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]
    self.move(gem1.pos)

(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”.


#7

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


#8

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]
	self.move(gem0.pos)

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)

#9

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?


#10

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.


#11

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…


#12

that is the same error that i get to.


#13
  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 :))