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

Problem| Rednet, send redstone pulses via masseges

Started by alontraitel, 20 December 2012 - 10:10 PM
alontraitel #1
Posted 20 December 2012 - 11:10 PM
hello :D/>
i have a problem in my CC creataion
i'm trying to send a redstone pulse via rednet, frim some reason it dosn't work..
here is my coeds:

sender:


and the if command goes on from 0 to 9.


receiver:



the problem is in the receiver, it doesn't reconize the input.
in the sender i see no problem..

plz help me :D/>
remiX #2
Posted 20 December 2012 - 11:57 PM
rednet.receive() needs returns 3 values, senderID, message and distance. Change it to:
senderID, number = rednet.receive()
alontraitel #3
Posted 21 December 2012 - 12:07 AM
ok, but i dont know the ID of my sender, how can i get it ?
theoriginalbit #4
Posted 21 December 2012 - 12:10 AM
snip. sorry read it wrong.

Edit: Will it always be the same computer? or different ones?
alontraitel #5
Posted 21 December 2012 - 12:13 AM
i have a main computer that send numbers to 9 computers that send a redstone signal.
in the main computer i enter the number and then i need that the computer with the number i entered will send a redstone pulse..
for exmple: if i enter in the main computer the number 5 then the fifth computer will send a redstone pulse :D/>
theoriginalbit #6
Posted 21 December 2012 - 12:14 AM
ok so the computer number that you enter for the signal to send to, is it the computer id or is it just a number you have given to it?
alontraitel #7
Posted 21 December 2012 - 12:17 AM
it is just a number i have given to it, i have no idea what is the IDs of the computers because i have more comuters machines beside this creation .
JoshhT #8
Posted 21 December 2012 - 12:18 AM
Here's what you need, just the very bare and basics of it.
Obviously you still need to open the rednet signal and all that jazz.

Sender code.

while true do
  local x = read()

  rednet.broadcast(x)
  sleep(2)
end

Receiver code.

while true do
  local sender, msg = rednet.receive()

  if msg == "4" then
    rs.setOutput("back", true)
    sleep(5)
    rs.setOutput("back", false)
  end
  sleep(1)
end
JoshhT #9
Posted 21 December 2012 - 12:19 AM
Or you could go one better, and actually send a message to individual computers, instead of just broadcasting?
theoriginalbit #10
Posted 21 December 2012 - 12:22 AM
Or you could go one better, and actually send a message to individual computers, instead of just broadcasting?

To do this he would need to know their id, which means he would need to broadcast a request message, analyse the response and then store their ids in a table, then look at the table later to send it back. Or he could just use the simple broadcast you suggested if it wont effect any other builds :)/>
alontraitel #11
Posted 21 December 2012 - 12:25 AM
Here's what you need, just the very bare and basics of it.
Obviously you still need to open the rednet signal and all that jazz.

Sender code.

while true do
  local x = read()

  rednet.broadcast(x)
  sleep(2)
end

Receiver code.

while true do
  local sender, msg = rednet.receive()

  if msg == "4" then
	rs.setOutput("back", true)
	sleep(5)
	rs.setOutput("back", false)
  end
  sleep(1)
end


thank you very very very much !!!
it work LOL :D/>
JoshhT #12
Posted 21 December 2012 - 12:30 AM
Here's a simple little thing I put together, to further explain my second suggestion.
With this code, it will only send the message to one specific computer you want, but you still only have to type in numbers 1 - 9 or whatever.
OP should use this if broadcasting interferes with other programs.


--Sender code.
local comps = { 4, 7, 11, 12, 13, 16, 19, 20 }

local x = read()

rednet.send(comps[x], "pulse bitch")

--Receiver code.
local senderID, msg = rednet.receive()

if msg == "pulse bitch" then
  rs.setOutput("back", true)
  sleep(5)
  rs.setOutput("back", false)
end
theoriginalbit #13
Posted 21 December 2012 - 12:32 AM
Here's a simple little thing I put together, to further explain my second suggestion.
With this code, it will only send the message to one specific computer you want, but you still only have to type in numbers 1 - 9 or whatever.
OP should use this if broadcasting interferes with other programs.


--Sender code.
local comps = { 4, 7, 11, 12, 13, 16, 19, 20 }

local x = read()

rednet.send(comps[x], "pulse bitch")

--Receiver code.
local senderID, msg = rednet.receive()

if msg == "pulse bitch" then
  rs.setOutput("back", true)
  sleep(5)
  rs.setOutput("back", false)
end

the receiver code at the very least should be in a while true do loop.
JoshhT #14
Posted 21 December 2012 - 12:36 AM
the receiver code at the very least should be in a while true do loop.

Yes well of course. I just couldn't be bothered typing it out. Hahha.