Posted 01 April 2014 - 11:57 AM
Hey, I want to make a rednet network using relays. I use rednet.broadcast(), and it works well with one relay but if I add more they start bouncing the message between them creating horrible lag. What can I do to stop that?
My code so far:
Send:
Relay:
Receiver:
BTW Hello everybody, my first post! :)/>
Edit: Heh, admin approval took so long that I solved this problem and finished my mail system :P/>
My code so far:
Send:
rednet.open("right")
rednet.send(7,os.getComputerID()) --7 is the ID of the nearest relay
rednet.send(7, "10") --10 is the ID of the receiving computer
rednet.send(7, "foo") --Message
Relay:
rednet.open("right")
while true do
id, sendid = rednet.receive() --Sender's ID
id, recvid = rednet.receive() --Receiver's ID
id, msg = rednet.receive() --Message
sendid = tonumber(sendid)
recvid = tonumber(recvid)
rednet.broadcast(sendid)
rednet.broadcast(recvid)
rednet.broadcast(msg)
end
Receiver:
rednet.open("right")
function receive()
id, sendid = rednet.receive()
id, recvid = rednet.receive()
if recvid == os.getComputerID() then
id, msg = rednet.receive()
print(sendid..": "..msg)
end
end
function something() --That will later be the sending function
print("Waiting for messages...")
end
while true do
parallel.waitForAll(receive, something)
end
BTW Hello everybody, my first post! :)/>
Edit: Heh, admin approval took so long that I solved this problem and finished my mail system :P/>
Edited on 01 April 2014 - 12:51 PM