我最近一直致力于制造一台机场计算机,让飞机不会相互着陆。出于某种原因,每次我运行我的程序时,它都会给我一个错误信息。我有另一个程序也会收到错误消息,将所有传入的消息打印到监视器上。这是我的代码:
程序1的错误消息(此消息仅在收到消息后发生:
[startup:9:尝试比较__le上的nil和数字]
程序2的错误消息:
[监视器:2:尝试呼叫nil]
第一个程序:
shell.openTab("monitor")
local Landing_open = true
rednet.open("top")
while true do
local id, message, distance = rednet.receive()
if message == "Requesting Landing" and distance <= 500 and Landing_open == true then
rednet.send(id, "Landing is granted. Please respond with Landing finished when you exit the runway.")
Landing_open = false
elseif message == "Requesting Landing" and distance>500 then
rednet.send(id, "Landing is not granted. Please try again when you are closer to the airport,")
elseif message == "Requesting Landing" and Landing_open == false then
rednet.send(id, "Landing is not granted. Please try again later.")
elseif message == "Landing Finished" then
rednet.send(id, "Roger that")
Landing_open = true
elseif message == "Airports" then
rednet.send(id, "Melee Airport")
end
end
下一个计划:
local monitor = peripheral.wrap("left")
monitor.setCursorPos(1,1)
while true do
local x, y = monitor.getCursorPos()
if y > 10 then
monitor.clear()
monitor.setCursorPos(1,1)
end
id, message,distance = rednet.receive()
monitor.write(id)
monitor.write(message)
monitor.write(distance)
end
答案 0 :(得分:0)
startup
)正在抱怨,因为“LE”失败转换为“小于或等于”,仅与distance <= 500
一起发生。因此,distance
由于某种原因未设置为数字。在检查rednet.receive docs时,看起来第三个返回值是protocol
,它声称是“字符串”。monitor
。