Jump to content




Rednet Confirmation When Sent


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

#1 ILoveZerg

  • New Members
  • 1 posts

Posted 20 December 2012 - 03:55 AM

I am trying to have a system where a computer can send a rednet message and will continue to send the message until it recieves a confimation message back. I cannot seem to thnk of a way to do this. Any help would be appreciated.

Thanks

#2 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 20 December 2012 - 04:03 AM

You could probably just have a loop, then break out of it when the signal is valid.

local id, msg
while true do
  rednet.send(someID, someSignal)
  id, msg = rednet.receive(5)
  if id and msg then break end
end
-- do stuff

This script basically sends a signal to whatever ID, then waits 5 seconds for a response. If it gets a response, it gets out of the loop. Otherwise, it just goes back to the beginning and try again.

EDIT: Just realized you could do this:
local id, msg
while not id and not msg do
  rednet.send(someID, someSignal)
  id, msg = rednet.receive(5)
end
-- do stuff

But do whatever works for you.

#3 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 20 December 2012 - 12:35 PM

I would probably do something that more replicates networking in real life by doing the following:
  • Send out message
  • Wait for an "ACK" to be sent back from that same computer (this means all computers need to be setup to send an "ACK" back after receiving any message except an "ACK", and making it wait for an "ACK" from the computer it sent to, means it wont bug out on broadcasts or other terminals sending an "ACK")
  • If no "ACK" in say 1 second (should theoretically be enough time, if not bump it up :) ) send message again until ACK received.
You could just do what Kingdaro said, however the one downside to this is if you are on a server, someone might send out a dummy message and could screw up your entire system since all terminals listen for a message. adding checking for a specific computer ID and message is the way to go if that concerns you. :)

Hope this helps :)

#4 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 21 December 2012 - 06:24 AM

View PostTheOriginalBIT, on 20 December 2012 - 12:35 PM, said:

You could just do what Kingdaro said, however the one downside to this is if you are on a server, someone might send out a dummy message and could screw up your entire system since all terminals listen for a message. adding checking for a specific computer ID and message is the way to go if that concerns you. :)/>
One liiiiine~
local id, msg
while true do
  rednet.send(someID, someSignal)
  id, msg = rednet.receive(5)
  if id == someID then break end
end


#5 ChunLing

  • Members
  • 2,027 posts

Posted 21 December 2012 - 07:28 AM

That's...not one line. Or even one liiiiine~.

And for the love of Cloudy's pet peeves, use:
local id, msg
repeat
  rednet.send(someID, someSignal)
  id, msg = rednet.receive(5)
until id == someID
It is also a pet peeve of mine as well.

Oh wait, I just realized that it was a one line modification of your previous code.

Edited by ChunLing, 21 December 2012 - 07:30 AM.


#6 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 21 December 2012 - 11:54 AM

View PostKingdaro, on 21 December 2012 - 06:24 AM, said:

View PostTheOriginalBIT, on 20 December 2012 - 12:35 PM, said:

You could just do what Kingdaro said, however the one downside to this is if you are on a server, someone might send out a dummy message and could screw up your entire system since all terminals listen for a message. adding checking for a specific computer ID and message is the way to go if that concerns you. :)/>
One liiiiine~
local id, msg
while true do
  rednet.send(someID, someSignal)
  id, msg = rednet.receive(5)
  if id == someID then break end
end

And again what if he doesn't want to program all the computer IDs into the program.

#7 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 21 December 2012 - 01:27 PM

View PostChunLing, on 21 December 2012 - 07:28 AM, said:

That's...not one line. Or even one liiiiine~.

And for the love of Cloudy's pet peeves, use:
local id, msg
repeat
  rednet.send(someID, someSignal)
  id, msg = rednet.receive(5)
until id == someID
It is also a pet peeve of mine as well.
Yeah, this makes more logical sense, but eh. Either one works.

View PostTheOriginalBIT, on 21 December 2012 - 11:54 AM, said:

And again what if he doesn't want to program all the computer IDs into the program.
What, like command line arguments?

local id, msg
while true do
  rednet.send(tonumber(({...})[1]), someSignal)
  id, msg = rednet.receive(5)
  if id == someID then break end
end


#8 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 21 December 2012 - 01:40 PM

View PostKingdaro, on 21 December 2012 - 01:27 PM, said:

What, like command line arguments?

Nah I meant more like one of the systems I used to run. I was adding a new computer every day or so and I didn't then want to go back around to all the computers just to add that new computers ID to a list so they could talk to it, so i made the code dynamic so that all i do is tell the new one what it is and then it broadcasts to the rest what it is, and then they all add it into their table and the save file so they can communicate later.

#9 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 21 December 2012 - 01:47 PM

So it's sort of like, you have one computer, with a secret rednet "password" that you send in order to have that computer be able to send and receive signals?

#10 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 21 December 2012 - 01:53 PM

yeh basically.

#11 ChunLing

  • Members
  • 2,027 posts

Posted 21 December 2012 - 02:04 PM

You could also make it so that the computer had to be in a specific area, as confirmed by the distance to a few other computers.

But that's doesn't change the functionality of the part that uses the ID's, it just changes how they get into the program.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users