Posted 04 June 2013 - 09:54 AM
Hi All,
I have a function that is meant to dynamically change the size of a 3D Array or table but it keeps breaking saying that it returns value nil because it is out of bounds. Here is the code for it:
I know it's not very well commented but the idea is that it is meant to make a new table with the changed dimensions, and then superimpose the data of blocks over the new table and finally overwriting blocks with the new temp table.
The length width and height are changed by one either incremented or decremented but only one at a time.
I'm not sure if I explained it clearly enough, if not let me know and I'll try explain in more detail.
Thanks all, James
I have a function that is meant to dynamically change the size of a 3D Array or table but it keeps breaking saying that it returns value nil because it is out of bounds. Here is the code for it:
function resize()
temp = { }
for h=1, height do
table.insert( temp , { } )
for y=1, length do
table.insert ( temp[h], { } )
for x=1, width do
num = 16
if #blocks <= height then
if #blocks[h] <= length then
if #blocks[h][y] <= width then
num = blocks[h][y][x]
end
end
end
table.insert( temp[h][y] , num )
end
end
end
blocks = temp
end
I know it's not very well commented but the idea is that it is meant to make a new table with the changed dimensions, and then superimpose the data of blocks over the new table and finally overwriting blocks with the new temp table.
The length width and height are changed by one either incremented or decremented but only one at a time.
I'm not sure if I explained it clearly enough, if not let me know and I'll try explain in more detail.
Thanks all, James