Hi,
if you draw this grid on a paer with the proper id, then you'll find it easier to work the algorythm out.
say you have a 4 by 4 grid, ( make it 3d when you will understand it in a 2d grid)
each cell is labelled by it's x and y index:
00 10 20 30 40
01 11 21 31 41
02 12 22 32 42
03 13 23 33 43
04 14 24 34 44
so now, say you are in cell 32, if you want to query for adjacent cubes, you need to call:
21, 31, 41, 22, 42,23, 33, 43
if you try to find the mathematical logic behind it, take the x index: 3, you need to query cells that are 1 less than 3, equal to 3 and one more than 3, so 2, 3 and 4
same on the y axis, so you can create an algorythm that count from x-1 to x+1, and inside this loop, you can from y-1 to y+1.
inside this small set of loop, you will need to verify that the cell you construct exists in the first place ( if you are on 34, 35 doesn't exist) , and that you don't check your own cell.
Does that make sense?
bye,
Jean