J
Jesse Jurman
I am trying to make a 3D grid using an Array of Arrays of Arrays but am
having trouble storing a single point with a value:
#2 by 2 by 2 grid
@grid = Array.new(2, Array.new(2, Array.new(2, "Null")))
#Point (x, y, z)
#Point (0, 1, 1)
@grid[0][1][1] = 'd'
#Print several points in grid
puts @grid[0][0][1]
puts @grid[0][1][1]
puts @grid[1][1][1]
puts @grid[0][0][0]
puts @grid[0][1][0]
puts @grid[1][1][0]
The code returns all values with z = 1 as 'd' and z = 0 as 'null'... It
should really be only making the point (0, 1, 1) as 'd' right?!?!?
If the above line "@grid[0][1][1] = 'd'" is changed, the only value that
will change the results is the z value...
I want it so that only "puts @grid[0][1][1]" returns 'd'... The actual
code contains more methods and stuff, but I think I've isolated the
problem to this... Any info, tutorials, links, or code would be greatly
appreciated.
having trouble storing a single point with a value:
#2 by 2 by 2 grid
@grid = Array.new(2, Array.new(2, Array.new(2, "Null")))
#Point (x, y, z)
#Point (0, 1, 1)
@grid[0][1][1] = 'd'
#Print several points in grid
puts @grid[0][0][1]
puts @grid[0][1][1]
puts @grid[1][1][1]
puts @grid[0][0][0]
puts @grid[0][1][0]
puts @grid[1][1][0]
The code returns all values with z = 1 as 'd' and z = 0 as 'null'... It
should really be only making the point (0, 1, 1) as 'd' right?!?!?
If the above line "@grid[0][1][1] = 'd'" is changed, the only value that
will change the results is the z value...
I want it so that only "puts @grid[0][1][1]" returns 'd'... The actual
code contains more methods and stuff, but I think I've isolated the
problem to this... Any info, tutorials, links, or code would be greatly
appreciated.