我的电脑游戏lua程序需要帮助 [英] I need help for my lua program in computercraft

查看:117
本文介绍了我的电脑游戏lua程序需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在研究一个项目,该项目制造的是能够防止飞机相互降落的机场计算机.由于某种原因,每次我运行程序时,都会给我一条错误消息.我还有另一个程序也会获取错误消息,该程序将所有传入的消息打印到监视器上.这是我的代码:

I have been recently working on a project to make an airport computer that keeps planes from landing on each other. For some reason, every time I run my program, it gives me an error message. I have another program that also gets error messages, that prints all the incoming messages onto a monitor. Here is my code:

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

Error message for program 1(this message only occurs after it receives a message:

[startup:9:尝试比较__le的nil和数字]

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

程序2的错误消息:

[显示器: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

推荐答案

  • 程序1(startup)抱怨,因为"LE"失败,翻译为小于或等于",仅在distance <= 500下出现.因此,出于某些原因,distance未被设置为数字.在检查 rednet.receive docs 时,它看起来像第三个返回值是protocol,它声称成为字符串".
  • 程序2失败,因为第1行中的呼叫由于某种原因未设置monitor.
    • Program 1 (startup) is complaining because of a "LE" fail which translates to "less than or equals" which only occurs with distance <= 500. So distance is not being set to numeric for some reason. In checking the rednet.receive docs it looks like the third return value is protocol which it claims to be a "string".
    • Program 2 is failing because the call in line 1 is not setting monitor for some reason.
    • 这篇关于我的电脑游戏lua程序需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆