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

[LUA] RedNet Computer to Computer communication!

Started by PyroGodz, 01 October 2012 - 02:41 AM
PyroGodz #1
Posted 01 October 2012 - 04:41 AM
Hello everyone, currently setting up a minecart station (which will eventually have turtles storing things from chest carts that arrive at the station, which is why I need rednet)

Right now I'm sort of 'beta-testing'. I am simply detecting if a cart has arrived, sending a message to a computer, that computer, then reads the message, if the message is "Cart2", it will wait 5 seconds, then send a message back to the detector computer, which should send the cart away. These are my programs:

Detecting Computer

local delay = 5
term.clear()
term.setCursorPos(1,1)
while true do
if redstone.getInput("bottom") then
rednet.send(7, "Cart2")
print(textutils.formatTime(os.time(),false)..": Minecart arrived at bay.")
senderId, message = rednet.receive()
if message == "SendCart2" then
redstone.setOutput("back", true)
print(textutils.formatTime(os.time(),false)..": Minecart left bay.")
sleep(2)
redstone.setOutput("back", false)
end
end
sleep(0.1)
end

Receiving Computer:

term.clear()
while true do
senderId, message = rednet.receive()
if message == "Cart2" then
  sleep(5)
  rednet.send(4, "SendCart2")
  end
  sleep(0.1)
end

The receiving computer does print that a minecart arrived.

EDIT: It appears one of the modems was off, although now once I add:
print(textutils.formatTime(os.time(), false)": Minecart arrived at bay two.")
onto the receiving computer, below line 4, the OSTime never prints, and the message is never sent, although there is no problem with that code because I have the same exact code in my sending computer for local logs. Thanks! :)/>/>
PonyKuu #2
Posted 01 October 2012 - 05:58 AM
Are you sure that the corresponding compurter ID's are 7 and 4?
PyroGodz #3
Posted 01 October 2012 - 05:59 AM
Are you sure that the corresponding compurter ID's are 7 and 4?

Yes, I'm 100% sure of that, because when I remove the line that is supposed to print the time, everything works perfectly fine.
mrSLIMEguy #4
Posted 01 October 2012 - 08:57 AM
By the way, you have to put .. in your print(textutils.formatTime(os.time, false)..": Minecart was sent")