Confused object references

I’m in the rather drawn out process of trying to totally rewrite my Gothic Vaults script to provide far more sophisticated and customisable results. However I am having problems with the following code (Abbreviated here):


p = [[None]*rowlength]*steps

row=0
for z in [i*stepsize for i in range(steps-1)]+[height]:
	k=0
	for i in range(numangles):
		...
		for j in range(numpoints):
			... x and y calculated here
			p[row][k]=(x, y, z)
			k+=1
		for j in range(numpoints-1,-1,-1):
			... x and y calculated here
			p[row][k]=(x, y, z)
			k+=1
	row+=1

This however is resulting in the z values of all points being equal. When I check the values in the middle of the loop they are initially correct but change every time z changes. How do I get the value of z rather than a reference to it?

Neil.

Entirely unconstructive post but…

Yay! Thanks neil, it would be really good to have more features for the vaults. I remember having much fun with them. I’m afraid that while I might be able to help with other languages, Python’s not my forte - good luck!

I’ve finally worked it out! My problem was not with z at all but with how I created an empty 2-d array in the first place. I have replaced it with just appending things to an empty list and it works perfectly. The copies of the lists making up the array were all the same list.

This is what I have ended up with:


p = []

for z in [i*stepsize for i in range(steps-1)]+[height]:
	p.append([])
	for i in range(numangles):
		...
		for j in range(numpoints):
			... x & y calculated here
			p[-1].append((x, y, z))
		for j in range(numpoints-1,-1,-1):
			... x & y calculated here
			p[-1].append((x, y, z))

I hopefully will be able to get something concrete (or maybe stone would be better!) done in the near future. I’m glad that people seem to be interested in such a specific, esoteric script - certainly my webstats say that 96 people have downloaded my copy of the file and others will have downloaded Crouch’s copy.

Neil.