I'm going to interpret this as you've given a location, say (50, 50) and need to check (49, 49) through (51, 51) for something. This is easily done with a few pieces of code:
Use this function to safely get values from the matrix:
Code: Select all
function getFromNodeMap(tableName, row, column)
local row = tableName[row]
if type(row)=="nil" then return 0 end -- Or some terminal value that's acceptable
local value = tableName[column]
if type(value)=="nil" then return 0 end -- Or some terminal value that's acceptable
return value
end
Now, it's safe to pull the 8 surrounding values:
Code: Select all
function getValuesAround(tableName, row, column)
local values = {}
for y = row-1, row+1 do
for x = column-1, column+1 do
if y~=row and x~=column then
values[#values+1] = getFromNodeMap(tableName, y, x)
end
end
end
return values
end