[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Sticky Variables: Terrain Loading
"Kris Schnee" <kschnee@xxxxxxxxxx> wrote:
> I've encountered another case of variables being taken as references
> rather than values.
In Python, variables are always just names.
Or, said differently, "All variables are references":
http://rg03.wordpress.com/2007/04/21/semantics-of-python-variable-names-from-a-c-perspective/
I tried to reproduce the problem you were having, using the following code:
landList=[]
SZ=10
for y in range(SZ):
for x in range(SZ):
if x>y:
terrain = "water"
else:
terrain = "grass"
landList.append(terrain)
del terrain
print landList
It works as I expect (and as you were originally expecting) - landList
gets filled up with both water and grass.
I did notice that you were using "y" as both a coordinate and as a flag
for whether the current pixel is yellow. Do you still have trouble if you
don't reuse "y" in this way?
-Dave LeCompte