Jump to content




Rednet relaying messages


  • You cannot reply to this topic
4 replies to this topic

#1 Heroj04

  • Members
  • 32 posts

Posted 14 September 2012 - 09: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

#2 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 14 September 2012 - 09: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.

#3 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 14 September 2012 - 09: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.

#4 Heroj04

  • Members
  • 32 posts

Posted 14 September 2012 - 09:50 PM

View PostCranium, on 14 September 2012 - 09:39 PM, said:

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


#5 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 15 September 2012 - 02: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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users