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

Rednet Problems

Started by YaYaBinks3, 14 February 2014 - 09:24 AM
YaYaBinks3 #1
Posted 14 February 2014 - 10:24 AM
Hey guys.
I've made a system where there are 3+ computers. Each one of them can toggle a redstone output.
The redstone output makes some sticky pistons go up, allowing some Sentry Turrets from FTB Unleashed to shoot.

However, for some reason, the computers that can toggle the pistons work and all, but none of them send messages to each other. I'm using rednet.broadcast to send a message to every computer. However, the computer that sent the broadcast can only receive a message from the mother computer (the one that sends out the redstone output)

Computer1 - Computer 2
|
Broadcasts 'turretToggle'
to Mother
computer
|
--------|---------
Mother computer sends redstone output
|
Mother computer broadcasts 'turreton' or 'turretoff'

Computer1 and Computer2 are supposed to receive these two messages, but the one who broadcasted to the mother computer is the only one to receive the message.
Can someone help?
Here's the code for Computer1 and Computer2:


side = "right"
rednet.open(side)
function clear()
term.clear()
term.setCursorPos(1,1)
end
clear()
print("Press X to toggle the turrets!")
xxx,key = os.pullEvent("char")
id,msg,dist = os.pullEvent("rednet_message")
function rednetxx()
id,msg,dist = os.pullEvent("rednet_message")
if msg == "turreton" then
clear()
print("Turrets are off!")
elseif msg == "turretoff" then
clear()
print("Turrets are on!")
end
end
function keysxx()
xxx,key = os.pullEvent("char")
if key == "x" then
key = ""
rednet.broadcast("toggleTurret")
end
end
while true do
parallel.waitForAny(rednetxx,keysxx)
end

Here's the code for the Mother Computer:


rednet.open("top")
ev,id,msg,dist = os.pullEvent("rednet_message")
output = false
while true do
os.pullEvent("rednet_message")
if ev == "rednet_message" then
if msg == "toggleTurret" then
output = not output
if output == true then
rednet.broadcast("turreton")
redstone.setOutput("left",true)
redstone.setOutput("right",true)
elseif output == false then
rednet.broadcast("turretoff")
redstone.setOutput("left",false)
redstone.setOutput("right",false)
end
end
end
end
tesla1889 #2
Posted 14 February 2014 - 10:31 AM
in the first code block, why do you call os.pullEvent("rednet_message") the first time?

also, in the second block, you never update ev, id, msg, and dist in the while loop

Edit: in the first block, you're missing the event variable when you call os.pullEvent. even if you specify an event to pull, os.pullEvent returns the event first, before the parameters
Edited on 14 February 2014 - 09:33 AM
YaYaBinks3 #3
Posted 14 February 2014 - 10:39 AM
Let me look..

I just tried doing that.

Removing the first block thingy you told me about didn't do much.

At the end of the second block I did:

id = nil
msg = nil
dist = nil
Didn't make a difference either :/

EDIT: Just checking your new idea..

Thank you!!! It worked!
Edited on 14 February 2014 - 09:38 AM