【问题标题】:I need help for my lua program in computercraft我需要计算机技术中的 lua 程序的帮助
【发布时间】:2015-08-03 01:51:44
【问题描述】:

我最近一直在做一个项目,以制造一台可以防止飞机相互降落的机场计算机。出于某种原因,每次我运行我的程序时,它都会给我一条错误消息。我有另一个程序也收到错误消息,它将所有传入的消息打印到监视器上。这是我的代码:

程序 1 的错误消息(此消息仅在收到消息后出现:

[startup:9: 尝试比较 __le on nil 和 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

【问题讨论】:

标签: lua computercraft


【解决方案1】:
  • 程序 1 (startup) 正在抱怨,因为“LE”失败转换为“小于或等于”,仅在 distance &lt;= 500 中出现。所以 distance 由于某种原因没有被设置为数字。在检查rednet.receive docs 时,看起来第三个返回值是protocol,它声称它是一个“字符串”。
  • 程序 2 失败,因为第 1 行中的调用由于某种原因未设置 monitor

【讨论】:

  • monitor 已设置,否则会抛出尝试index nil。我猜setCursorPos 中有错字,或者监视器的元表设置不正确。但是我们需要更多的代码来解决这个问题:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-03
  • 1970-01-01
  • 2013-02-19
相关资源
最近更新 更多