Improved status response.
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user