[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Sticky Variables: Terrain Loading



"Kris Schnee" <kschnee@xxxxxxxxxx> wrote:

>              for y in range(self.size):
>                  for x in range(self.size):
>                      rgb = the_map.get_at((x,y))
>                      r = rgb[0] > 100
>                      g = rgb[1] > 100
>                      b = rgb[2] > 150
>                      y = r and g

I suspect if you were to add a debug line to print out (x,y) before doing
the get_at, you'd see something like the following:

(0, 0)
(1, False)
(2, False)
(3, False)
(4, False)
...

That ought to look suspicious. I wouldn't be surprised that it continued
to run, because False can be converted to 0 (and will be), so really,
you're just looking at the edge of your map. Similarly, True converts to
1, so depending on the specific patterns in the 0 and 1 rows of your map,
you might get bands of color, checkerboard patterns, or one solid color,
the last of which sounds like what you happened to hit this time.

This doesn't have to do with the details of immutable object identity,
it's strictly a result of stomping the outer loop index inside your inner
loop, which would be a problem in other languages, too.


-Dave LeCompte