From 7e7aa9febcbfc63d24044e09c27c960e53c05824 Mon Sep 17 00:00:00 2001 From: Harrison Deng Date: Mon, 3 May 2021 14:49:44 -0500 Subject: [PATCH] Improved status response. --- minehost.lua | 8 ++++++-- mineleader.lua | 16 +++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/minehost.lua b/minehost.lua index cf75844..29979a0 100644 --- a/minehost.lua +++ b/minehost.lua @@ -30,7 +30,6 @@ local FAILED = "failed" running = true local modem = peripheral.find("modem") - print("Checking for modem.") if (modem == nil) then error("Modem not found.") @@ -100,7 +99,12 @@ end local function handleMessage(sender, type, data) if type == LOG then - print("[" .. sender .. "]: " .. data["log"] .. " : " .. (data["content"]["n"] >= 1 and tostring(data["content"][1]) or "")) + print("[" .. sender .. "]: " .. data["log"] .. ": " .. (data["content"]["n"] >= 1 and tostring(data["content"][1]) or "")) + if data["log"] == STATUS then + print("Relative position: " .. tostring(data["content"][1]["relative_position"]["coordinates"])) + print("Position" .. tostring(data["content"][1]["position"]["coordinates"])) + print("fuel: " .. tostring(data["content"][1]["fuel"])) + print("current task: " .. data["content"][1]["task"]) elseif type == REQUEST then handleRequest(sender, data["request"], data["content"]) end diff --git a/mineleader.lua b/mineleader.lua index 4c9e25b..19d74cf 100644 --- a/mineleader.lua +++ b/mineleader.lua @@ -221,13 +221,13 @@ local function orient(v, forward, right) print("Orientation complete.") end -local function attemptStartTask(f, ...) +local function attemptStartTask(name, f, ...) sendLog(TASK, "Attempting to start task.") if task ~= nil then sendLog(FAILED, "Unable to start task due to another task running.") return end - task = f + task = {name=name, func=f, args=arg} taskArgs = arg end @@ -314,7 +314,8 @@ end local function executeTasks() while running do if task ~= nil then - task(unpack(taskArgs)) + sendLog(TASK, "Executing task: " .. task["name"]) + task["func"](unpack(task["args"])) task = nil end sleep(5) @@ -349,11 +350,11 @@ local function listen() if heading ~= nil then print("Using actual coordinates.") sendLog(MOVETO, "Using actual coordinates to move.") - attemptStartTask(moveTo, vector.new(x,y,z), heading, rightAxis) + attemptStartTask(MOVETO, moveTo, vector.new(x,y,z), heading, rightAxis) else print("Using relative coordinates.") sendLog(MOVETO, "Using relative coordinates to move.") - attemptStartTask(moveTo, vector.new(x,y,z), relHeading, relRightAxis) + attemptStartTask(MOVETO, moveTo, vector.new(x,y,z), relHeading, relRightAxis) end elseif data["request"] == MOVEBY then local x = data["content"][1] @@ -362,11 +363,11 @@ local function listen() if heading ~= nil then print("Using actual coordinates.") sendLog(MOVEBY, "Using actual coordinates to move.") - attemptStartTask(moveBy, vector.new(x,y,z), heading, rightAxis) + attemptStartTask(MOVEBY, moveBy, vector.new(x,y,z), heading, rightAxis) else print("Using relative coordinates.") sendLog(MOVEBY, "Using relative coordinates to move.") - attemptStartTask(moveBy, vector.new(x,y,z), relHeading, relRightAxis) + attemptStartTask(MOVEBY, moveBy, vector.new(x,y,z), relHeading, relRightAxis) end elseif data["request"] == STATUS then status = { @@ -381,6 +382,7 @@ local function listen() right=rightAxis }, fuel=turtle.getFuelLevel(), + task=task["name"] } sendLog(STATUS, status) elseif data["request"] == POSITION then