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

[rednet] Would this work?

Started by JGreen1996, 07 May 2012 - 10:19 AM
JGreen1996 #1
Posted 07 May 2012 - 12:19 PM
 
rednet.open("top")
rec = rednet.receive()

repeat
print(rec)
sleep(0.2)
until nil

would this work to print everything which gets broadcasted over rednet?
BigSHinyToys #2
Posted 07 May 2012 - 12:58 PM
no
this is the wrong section to ask for help so think your self luckie i will help you. please send all further help questions to the ask a pro section.

the variable rec will not change so it will print the same thing every time

use this


rednet.open("top")
while true do
event, var1, var2 = os.pullEvent()
if event == nil then
write("event is nill")
else
write("event is ".. event)
end

if var1 == nil then
write(" var1 is nill")
else
write(" var1 is "..var1)
end

if var2 == nil then
write(" var2 is nil")
else
write(" var2 is "..var2)
end
end
Grim Reaper #3
Posted 08 May 2012 - 03:48 AM
Like BigSHinyToys said, this code won't work. However, with minimal effort you could make it work! :)/>/>

Instead of

rednet.open("top")
rec = rednet.receive()
repeat
print(rec)
sleep(0.2)
until nil

You could try

rednet.open("top")
while true do -- Continues until terminated by the user or event specified
sender, message = rednet.receive(1.3) -- The argument stated here is a timeout,
or how long the machine will be receiving for before it jumps to the next line of code. This timeout will act as our sleep()
-- Also, rednet,receive() in its most basic form returns two values:
the id of the computer which sent the message, and the message which is self explanatory.

term.clear()
term.setCursorPos(1,1) -- Just clearing the screen
if sender == nil then print("Sorry! I got nothing...")
else print("Sender: "..sender.."nMessage: "..message)
end