31 posts
Posted 14 September 2012 - 10:34 PM
Hey I'm attempting to relay Rednet messages over 64 blocks with this code
function relay()
rednet.open("right")
local event, param1, param2, param3 = os.pullEvent("rednet_message")
If param1 == "88" then
rednet.broadcast(param2)
relay()
else
relay()
end
end
relay()
The message isn't passing throug, not making it to the last computer.
What's wrong here is it the if statement
3790 posts
Location
Lincoln, Nebraska
Posted 14 September 2012 - 10:39 PM
I think you are looking for rednet.receive() instead of os.pullEvent().
If you do use os.pullEvent(), I believe that the first parameter would come across as an integer/number. Try removing the quotes from "88", and it might work. Not sure what you have on the sending end though.
1604 posts
Posted 14 September 2012 - 10:44 PM
Yes, the problem is that the id (param1) is a number and you are comparing it to a string. Remove the quotes from the "88" and it should work.
Also, DON'T USE RECURSION TO MAKE LOOPS. It will overflow the stack after some time, use actual loops instead.
31 posts
Posted 14 September 2012 - 10:50 PM
I think you are looking for rednet.receive() instead of os.pullEvent().
If you do use os.pullEvent(), I believe that the first parameter would come across as an integer/number. Try removing the quotes from "88", and it might work. Not sure what you have on the sending end though.
I tried receive before but it didn't work so I tried os.pullEvent
I'm trying to make a program that you can type bomb on a pc to send a message to turtles 200 blocks up to start bombing (it's our company's defense/offense system for a nuclear war coming soon)
I had it written
function relay()
rednet.open("right")
local sID, message, MSGDis = rednet.receive()
rednet.broadcast(message)
end
1111 posts
Location
Portland OR
Posted 15 September 2012 - 03:33 AM
The MSGDis var is actually capturing the distance the message is being sent.
The output from rednet.receive() is the sender id, the message, and the distance the message was sent.
If you are sending additional information in the message that you need to use you will need to split it out of the message. rednet.send() only sends the ID and 1 message string.