Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function proxyFor(name, required)
- local address = component and component.list(name)()
- if not address and required then
- --error("missing component '" .. name .. "'")
- end
- return address and component.proxy(address) or nil
- end
- local drone = proxyFor("drone", true)
- local nav = proxyFor("navigation", true)
- local range = 15
- local charger = nil
- local farm = nil
- local storage = nil
- local function updateWaypoints()
- for _, w in ipairs(nav.findWaypoints(range)) do
- if w.label == "charger" then
- charger = w
- elseif w.label == "farm" then
- farm = w
- elseif w.label == "storage" then
- storage = w
- end
- end
- if charger == nil or farm == nil or storage == nil then
- error("waypoints missing")
- os.exit()
- end
- end
- -- Keep track of our own position, relative to our starting position.
- local px, py, pz = 0, 0, 0
- local function moveTo(x, y, z)
- if type(x) == "table" then
- x, y, z = x[1], x[2], x[3]
- end
- local rx, ry, rz = x - px, y - py, z - pz
- drone.move(rx, ry, rz)
- px, py, pz = x, y, z
- end
- while true do
- updateWaypoints()
- --moveTo(charger.position.x, charger.position.y, charger.position.z)
- end
Add Comment
Please, Sign In to add comment