0

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
michelem
  • 14,430
  • 5
  • 50
  • 66
  • You already asked questions about the exact same program here ( http://stackoverflow.com/q/31691023/4273199 ) a few days before opening this question. – Mischa Dec 04 '15 at 11:41

1 Answers1

0
  • 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.
chicks
  • 2,393
  • 3
  • 24
  • 40
  • 1
    `monitor` is set, otherwise it would throw an *attempt to __index__ nil*. I guess that either there's a typo in `setCursorPos` or that the metatable of monitor is not set correctly. But we'll need more code to figure that out :) – Henrik Ilgen Aug 03 '15 at 07:30