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

redstone input = command

Started by Lewis.holcombe, 24 February 2013 - 08:48 AM
Lewis.holcombe #1
Posted 24 February 2013 - 09:48 AM
Title: redstone input = command

Just a quick question I would like to ask.
So basically I would like it so if a powered redstone signal went into say the back of my computer it makes my computer run a program like startup or 'monitor top help' something like that? Can you do that?
SuicidalSTDz #2
Posted 24 February 2013 - 10:21 AM
You could do this:


side = --side the redstone is touching the computer
while true do
  event = os.pullEvent()
  if event == "redstone" and rs.getInput(side) == true then
   --run program
  end
end

EDIT: The side also must be defined as a string like so: side = "back"
Lewis.holcombe #3
Posted 24 February 2013 - 11:13 PM
Thanks!
SuicidalSTDz #4
Posted 25 February 2013 - 04:14 AM
No problem :)/>
Lewis.holcombe #5
Posted 25 February 2013 - 01:33 PM
S I have this program here an it works fine :)/> but I messed around for about an hour… Derp and couldn't figure out how to add a seccond event thing. So if a signal hits the top not the side for say it does a different command. So I will have 2 options?

side = –side the redstone is touching the computer
while true do
event = os.pullEvent()
if event == "redstone" and rs.getInput(side) == true then
–run program
end
end
SuicidalSTDz #6
Posted 25 February 2013 - 01:53 PM
Try this:

side = --side the redstone is touching the computer
tSide = --another side where redstone touches the computer
while true do
event = os.pullEvent()
if event == "redstone" and rs.getInput(side) == true then
--run program
elseif event == "redstone" and rs.getInput(tSide) == true then
--run other program
end

Just cleaned the code a bit:

side = --side the redstone is touching the computer
tSide = --another side where redstone touches the computer
while true do
event = os.pullEvent()
  if event == "redstone" then
   if rs.getInput(side) == true then
    --run program
   elseif rs.getInput(tSide) == true then
    --run other program
   end
 end
end
Shnupbups #7
Posted 25 February 2013 - 01:53 PM

side = "right"
side2 = "top"
while true do
event = os.pullEvent()
if event == "redstone" and rs.getInput(side) == true then
  --do stuff
elseif event == "redstone" and rs.getInput(side2) == true then
  --do other stuff
end
end
DAMNIT! NINJA'D!
SuicidalSTDz #8
Posted 25 February 2013 - 01:59 PM

side = "right"
side2 = "top"
while true do
event = os.pullEvent()
if event == "redstone" and rs.getInput(side) == true then
  --do stuff
elseif event == "redstone" and rs.getInput(side2) == true then
  --do other stuff
end
end
Lol, cleaned that up ;)/>

Also, remember that you could have SIX!.. programs that run if a redstone input is detected. The event = os.pullEvent() will wait for any event and store the result in the variable "event" as defined. The event is then compared to the event "redstone", if they don't match then it restarts the loop. Otherwise it will check if a defined side is being given a redstone input. Obviously a side must be powered or else the event would not be defined as a "redstone" event and would not reach this part of the program. If you have any questions regarding more input sides, events, or anything just ask and anyone here will be glad to help.
Lewis.holcombe #9
Posted 26 February 2013 - 04:50 AM
Cheers for all the help guys!
Lyqyd #10
Posted 26 February 2013 - 07:05 AM
I don't know why you thought you couldn't find this post, but it is right here.
SuicidalSTDz #11
Posted 26 February 2013 - 09:14 AM
No problem. Glad to help anytime.
Andrakon #12
Posted 26 February 2013 - 10:23 AM
This is going to be quite useful! Thanks SuicidalSTDz!
SuicidalSTDz #13
Posted 26 February 2013 - 10:30 AM
This is going to be quite useful! Thanks SuicidalSTDz!
No problem! ;)/> I went more in depth in the other thread labeled: Redstone Input = Command (advanced)
Lyqyd #14
Posted 26 February 2013 - 11:01 AM
Threads merged. Please stick to a single topic for a single question.
SuicidalSTDz #15
Posted 26 February 2013 - 11:18 AM
Threads merged. Please stick to a single topic for a single question.
Knew that was going to happen ;)/>
I guess he made a new thread asking a "similar" question since he couldn't find this thread (Which is odd)