组件:地址分析仪

此组件由地址分析仪方块提供。

组件名:geolyzer

回调函数:

下列代码片段可用于理解scan函数实际如何工作。它会扫描指定偏移处指定大小的区域,保存返回的数据以及相对于地质分析仪方块(或机器人)的准确偏移坐标,并打印这些数据。

local component = require("component")
local geolyzer = component.geolyzer
 
local offsetx = 4
local offsetz = -3
local offsety = -5
 
local sizex = 3
local sizez = 4
local sizey = 5
 
local map = {}
local scanData = geolyzer.scan(offsetx, offsetz, offsety, sizex, sizez, sizey)
local i = 1
for y = 0, sizey - 1 do
    for z = 0, sizez - 1 do
        for x = 0, sizex - 1 do
            -- 可看作是三维表:map[offsety + y][offsetz + z][offsetx + x] = scanData[i]
            map[i] = {posx = offsetx + x, posy = offsety + y, posz = offsetz + z, hardness = scanData[i]}
            i = i + 1
        end
    end
end
 
for i = 1, sizex*sizez*sizey do
    print(map[i].posx, map[i].posy, map[i].posz, map[i].hardness)
end

目录