问题
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:
Error message for program 1(this message only occurs after it receives a message:
[startup:9: attempt to compare __le on nil and number]
Error message for program 2:
[monitor:2:attempt to call nil]
First Program:
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
Next Program:
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:
- Program 1 (
startup
) is complaining because of a "LE" fail which translates to "less than or equals" which only occurs withdistance <= 500
. Sodistance
is not being set to numeric for some reason. In checking the rednet.receive docs it looks like the third return value isprotocol
which it claims to be a "string". - Program 2 is failing because the call in line 1 is not setting
monitor
for some reason.
来源:https://stackoverflow.com/questions/31773264/i-need-help-for-my-lua-program-in-computercraft