I'm just simply trying to store a bunch of blocks in a bunch of chunks. It's for a very simple voxel world. There are three class levels at the moment in the test code (I was going to play around with the pickle module and serializing): the world, chunks in the world, and blocks in the chunks.
This is the trace:
Traceback (most recent call last): File "C:/Crayder/Scripts/pickle
test/pickle1.py", line 27, in <module> aWorld = world(); File
"C:/Crayder/Scripts/pickle test/pickle1.py", line 25, in __init__
self.chunks[cX][cY] = chunk(cX, cY); File "C:/Crayder/Scripts/pickle
test/pickle1.py", line 18, in __init__ self.blocks[bX][bY][bZ] =
block((self.x * 16) + bX, (self.y * 16) + bY, bZ); IndexError: list
index out of range
And here is the code:
class block:
def __init__(self, x, y, z, data = 0):
self.x = x;
self.y = y;
self.z = z;
self.data = data;
class chunk:
def __init__(self, x, y):
self.x = x;
self.y = y;
self.blocks = [];
for bX in range(16):
for bY in range(16):
for bZ in range(64):
self.blocks[bX][bY][bZ] = block((self.x * 16) + bX, (self.y * 16) + bY, bZ);
class world:
def __init__(self):
self.chunks = [];
for cX in range(16):
for cY in range(16):
self.chunks[cX][cY] = chunk(cX, cY);
aWorld = world();
print(aWorld.chunks[2][2].blocks[2][2][2]);
What am I doing wrong here?
list, not an array.