Fixed incorrect table fields being referenced.

This commit is contained in:
Harrison Deng 2021-05-03 14:21:07 -05:00
parent 40ff22f327
commit d0ba5a96de

View File

@ -327,10 +327,10 @@ local function listen()
local event, side, sendChannel, replyChannel, serialized, distance = os.pullEvent("modem_message") local event, side, sendChannel, replyChannel, serialized, distance = os.pullEvent("modem_message")
print("Recieved data...") print("Recieved data...")
local data = textutils.unserialise(serialized) local data = textutils.unserialise(serialized)
if data["token"] == TOKEN and data["recipient"] == UNIT then if data["token"] == TOKEN and data["recipient"] == UNIT and data["type"] == REQUEST then
print("Got content: " .. data["type"]) print("Got request: " .. data["request"])
if data["type"] == LUA_PREFIX then if data["request"] == LUA_PREFIX then
print("Executing: " .. data["content"][0]) print("Executing: " .. data["content"][0])
local f = loadstring(luaScript) local f = loadstring(luaScript)
if f ~= nil then if f ~= nil then
@ -342,7 +342,7 @@ local function listen()
else else
printError("Unable to load lua string.") printError("Unable to load lua string.")
end end
elseif data["type"] == MOVETO then elseif data["request"] == MOVETO then
local x = data["content"][1] local x = data["content"][1]
local y = data["content"][2] local y = data["content"][2]
local z = data["content"][3] local z = data["content"][3]
@ -355,7 +355,7 @@ local function listen()
sendLog(MOVETO, "Using relative coordinates to move.") sendLog(MOVETO, "Using relative coordinates to move.")
attemptStartTask(moveTo, vector.new(x,y,z), relHeading, relRightAxis) attemptStartTask(moveTo, vector.new(x,y,z), relHeading, relRightAxis)
end end
elseif data["type"] == MOVEBY then elseif data["request"] == MOVEBY then
local x = data["content"][1] local x = data["content"][1]
local y = data["content"][2] local y = data["content"][2]
local z = data["content"][3] local z = data["content"][3]
@ -368,7 +368,7 @@ local function listen()
sendLog(MOVEBY, "Using relative coordinates to move.") sendLog(MOVEBY, "Using relative coordinates to move.")
attemptStartTask(moveBy, vector.new(x,y,z), relHeading, relRightAxis) attemptStartTask(moveBy, vector.new(x,y,z), relHeading, relRightAxis)
end end
elseif data["type"] == STATUS then elseif data["request"] == STATUS then
status = { status = {
relative_position = { relative_position = {
coordinates=relativePos, coordinates=relativePos,
@ -383,11 +383,11 @@ local function listen()
fuel=turtle.getFuelLevel(), fuel=turtle.getFuelLevel(),
} }
sendLog(STATUS, status) sendLog(STATUS, status)
elseif string.find(content, POSITION) == 1 then elseif data["request"] == POSITION then
locatePosition() locatePosition()
elseif string.find(content, HEADING) == 1 then elseif data["request"] == HEADING then
determineHeading() determineHeading()
elseif string.find(content, QUARRY) == 1 then elseif data["request"] == QUARRY then
end end
end end
end end