My character wont do anything at all


coins = self.findItems()
coinIndex = 0
coin = coins[coinIndex]
while coinIndex < len(coins):    
    if coin.value == 3:
        posc = coin.pos
        cx = posc.x
        cy = posc.y
        self.moveXY(cx, cy)
    coinIndex += 1

plz help me it getts stuck on the line:
while coinIndex < len(coins)


You have read the FAQ, right? Then it should not be necessary to ask. But it is good that you show the intention to indent.

You can indent code with three backticks (```) before and after your code.

#There are 4 spaces in front of this


    #There are 4 spaces in front of this


If you point at your post with your mouse a “bar” of icon will fade in below it (the post), use the pencil icon to edit your post and add the `s J_F_B_M metioned.

In the mean time, I am assuming that your indention is correct and even if it isn’t what I am saying holds.

you are using “coinIndex” OUTSIDE the while loop, and not in it… this means that you only ever look at “one” coin… so your hero (unless there are other errors) does one of two things:

  • if coins[0] is gold - walks over to the first coin (coins[0]) and then appears to do nothing (when in fact they are continually walking to the position of the same coin over and over and over . . . being that they are already there, they effectively stand still. :wink:
  • if coins[0] is not gold - does nothing as that is what they are supposed to do when looking at a non-gold coin…


it gets stuck on the line:
while coinIndex < len(coins)

please help


Hmm, is it that you get stuck there? or is it that you have no loop around the coin getting while…

In other words what happens when there are no coins???

the while loop exits immediately because there is nothing to do.
then execution of your code ends, because there is nothing more to do.

you need some over arching always running loop . . . why?
Because there may be a split second as the level starts up when there are no coins -or- maybe there is a split second later on when you have picked up the coins so fast that the next one hasn’t appeared yet…