This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
mrcrocodile123's profile picture

having trouble with rednet!

Started by mrcrocodile123, 03 September 2012 - 10:27 AM
mrcrocodile123 #1
Posted 03 September 2012 - 12:27 PM
i have designed a menu program to turn lights on / off
however the lights seem to only turn on but not off?? any help

command computer:

while x ~= "exit" do
print("——————————")
print("MAIN MENU")
print('To access the lighting menu interface enter "lights"')
print('to access the generator menu interface enter "generators"')
print("——————————")
x=io.read()
if x == "lights" then
while y ~= "exit" do
print("——————————")
print("LIGHTING MENU")
print('To turn on the lighting system enter "on"')
print('To turn off the lighting system enter "off"')
print('To return to the Main Menu enter "exit"')
print("——————————")
y=io.read()
if y == "on" then
rednet.open("left")
rednet.send(13, "lights on")
rednet.close("left")
if y == "off" then
rednet.open("left")
rednet.send(13, "lights off")
rednet.close("left")
end
end
end
end
end


receiving computer:

rednet.open("left")
id, msg = rednet.receive()
if msg == "lights on" then
rs.setOutput("top", true)
sleep(2)
id, msg = rednet.receive()
if msg == "lights off" then
rs.setOutput("top", false)
os.reboot()
end
end

any help to fix my problem is appreciated thanks!
Kazimir #2
Posted 03 September 2012 - 01:11 PM
while x ~= "exit" do
print("------------------------------")
print("MAIN MENU")
print('To access the lighting menu interface enter "lights"')
print('to access the generator menu interface enter "generators"')
print("------------------------------")
x=io.read()
  if x == "lights" then
     while y ~= "exit" do
      print("------------------------------")
      print("LIGHTING MENU")
      print('To turn on the lighting system enter "on"')
      print('To turn off the lighting system enter "off"')
      print('To return to the Main Menu enter "exit"')
      print("------------------------------")
      y=io.read()
        if y == "on" then
          rednet.open("left")
          rednet.send(13, "lights on")
          rednet.close("left")
        elseif y == "off" then
          rednet.open("left")
          rednet.send(13, "lights off")
          rednet.close("left")
        end
     end 
  end
end


rednet.open("left")
id, msg = rednet.receive()
if msg == "lights on" then
  rs.setOutput("top", true) 
  sleep(2)
  id, msg = rednet.receive()
elseif msg == "lights off" then
  rs.setOutput("top", false) 
  os.reboot()
end
mrcrocodile123 #3
Posted 03 September 2012 - 06:08 PM
it still i having issues….
what are you using to write your coding out????