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

How Would I Make A Selector?

Started by jman263, 22 September 2012 - 07:53 PM
jman263 #1
Posted 22 September 2012 - 09:53 PM
I'm a little new to lua and computercraft. And trying to find so good tutorials is hard to come by. What I'm trying to do is make a selector switch. When imputing the id of a computer into another computer, it would make the specified computer send out a redstone signal.

If anyone cold help me with this, or even send me to a good tutorial, i would appreciate it greatly.
sjele #2
Posted 22 September 2012 - 09:58 PM
You can use rednet.
This code sends out a signal for 4 seconds then de activates siganl

code:

reciver:

while true do
id, msg = rednet.recive()
if msg == "on" then
rs.setOutput("side") --Change side to outout side
sleep(4)
rs.setOutput("side") --Change to side of output
sleep(4)
end
end

sender:

while true do
term.clear()
term.setCursorPos(1, 1)
write("Witch computer: ")
id = tonumber(read())
rednet.send(id, "on")
end

This should work. It is not tested
Anonomit #3
Posted 23 September 2012 - 07:28 PM
Make sure each computer has a modem on it. Here is the corrected code:

Sender:

rednet.open( "right" )
rednet.open( "left" )
rednet.open( "back" )
rednet.open( "top" )
rednet.open( "bottom" )

while true do
term.clear()
term.setCursorPos(1, 1)
write("Which computer: ")
id = tonumber(read())
rednet.send(id, "on")
end

Receiver:

side = "whatSideToOutputRedstone"	   --change to what side you want to output to
time = 4				 --change to how long you want receiving computer to output redstone for

rednet.open( "right" )
rednet.open( "left" )
rednet.open( "back" )
rednet.open( "top" )
rednet.open( "bottom" )

while true do
id, msg = rednet.receive()
if msg == "on" then
rs.setOutput(side, true) --Change side to outout side
sleep(time)
rs.setOutput(side, false) --Change to side of output
end
end