我需要在computercraft中的lua程序中得到帮助。

我最近在设计一个机场电脑程序,用于避免飞机互相降落。但是,每次运行我的程序时,都会出现一个错误消息。我还有另外一个程序,也会收到错误消息,而这个程序会将所有传入的消息输出到监视器上。以下是我的代码:

程序1的错误消息(只有在接收到消息后才出现此消息):

[startup:9: attempt to compare __le on nil and number]

程序2的错误消息:

[monitor:2:attempt to call 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
点赞
用户2002471
用户2002471
  • startup 程序抱怨发生了“LE”失败,这意味着“小于等于”,只有当 distance <= 500 时才会发生。因此,由于某种原因,distance 没有被设置为数字。在检查 rednet.receive 文档 时,发现第三个返回值是“协议”,它声称是一个“字符串”。
  • 第二个程序因为第一行的调用出现问题,由于某种原因没有设置 monitor
2015-08-02 17:40:16