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

[programming][redstone]

Started by The, 24 September 2012 - 08:31 PM
The #1
Posted 24 September 2012 - 10:31 PM
I am working on something where for the first time I need the computer to recieve input to trigger an output. I know this can be done with

rs.getInput("side")
but when i use this functionality the program bugs out. I need it to wait for an input which sets off an output. Would i do this by setting a variable for the input? I don't know how to use booleans in variables. If so, how exactly would this be done?

The program I am trying to write is for some buildcraft engines. After the computer recieves input from a redstone transport pipe, it activates a bunch of engines (to be more specific). Basically, I need it to wait for an item to pass by this redstone pipe and therefore turn it on.
Luanub #2
Posted 24 September 2012 - 10:34 PM
Try using events


local event, p1 = os.pullEvent("redstone")
if rs.getInput("side") then
--code
end

You can remove the "redstone" filter from the os.pullEvent() and set it up to accept redstone, rednet, or key inputs as triggers. Just check against the event variable to see what type of event fired.
The #3
Posted 24 September 2012 - 10:43 PM
Sorry sir, you lost me at "local." Please explain this "event" and "os.pullEvent" business.
Luanub #4
Posted 24 September 2012 - 10:59 PM
The local makes the variable's/functions after it local the the program, function, loop, etc that they are declared in. This will help avoid numerious issues. Use it when ever you can.

os.pullEvent() causes the program to yield until an event happens. It returns the event type and upto 5 parameters depending on the event type.

I suggest checking out the wiki for more information. OS API

event is the var i'm using to capture the event type, you can name it whatever you want.
The #5
Posted 24 September 2012 - 11:10 PM
Ok so then how would I set it to wait for rs.getInput to return true then run some code?
Luanub #6
Posted 25 September 2012 - 01:43 AM

local event, p1 = os.pullEvent("redstone")
if rs.getInput("side") then
--code
end

Like this
The #7
Posted 25 September 2012 - 01:45 AM
so os.pullEvent() waits for something to change just like read() waits for user input?
Luanub #8
Posted 25 September 2012 - 01:57 AM
Yes, it will yield the system until an event happens.
The #9
Posted 25 September 2012 - 07:13 PM
Thanks luanub, and please excuse me for being diffcult.