Near":11u6di4i said:I'll try an instance of Table, then.
and I didn't show the initialization, but it's there.
def init_multi_array(width) #Multi-Dimensional Array Creation
arr = []
for i in 0...width
arr[i] = []
end
return arr #Return multi-array
end
multi_arr = init_multi_array(10) #create a multi array with a width of 10
multi_arr[3][4] = "foo" #this will work to set
multi_arr[3][4] #=>"foo"
multi_arr[12] = "bar" #Note that this will work, because the first dimension of this multi array is just an array
multi_arr[12][3] #This will return an out of bounds exception (Since you just set multi_arr[12] to "bar" and there is no 4th character)
multi_arr[17][2] #This will get you an undefined method [] for nil because the 17th slot in your first dimension is nil
def get_dis(x, y)
dx = (@x - x) * -1
dy = (@y - y) * -1
return dx, dy
end
def update
dis = get_dis(0, 0)
p dis[0]
end
object = {}
key = [x, y, z]
object[key] = 'something'
#vs.
object = []
object[x] = []
object[x][y] = []
object[x][y][z] = 'something'