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

Redstone "True/False" Status w/ Refresh

Started by ZallCaTor, 03 November 2015 - 06:25 AM
ZallCaTor #1
Posted 03 November 2015 - 07:25 AM
So, I have a project, and its principal purpose is to monitor the status of machines. (I'm using Tekkit.)
I will start with the simplest question.
How do I get a computer to look for a redstone signal, and respond acordingly?
So far, here's what I got


if redstone.getInput("right", false) then
   redstone.setOutput("back", true) else
   redstone.setOutput("back", false)
end

This has given me much trouble. I want it to be a constantly refreshing program, that constantly looks for a true/false redstone signal, and returns a signal acordingly.
I've tried various loops, but to no effect, as the computer breaks the loop if it doesn't recieve an input for five seconds, which, is not the desired effect atm.

If anyone could get me headed in the right direction, that would be awesome.
Thanks.
Bomb Bloke #2
Posted 03 November 2015 - 08:04 AM
It looks like you want to do this:

while true do  -- Start a loop that repeats indefinitely.
  redstone.setOutput("back", not redstone.getInput("right") )  -- Set the rear output to the inverse of the right input.
  os.pullEvent("redstone")  -- Yield until a redstone state change occurs.
end

Note that redstone.getInput() accepts only one argument, that being the side you want the input from. It returns true or false based on whatever that input is.

Scripts that don't yield at least once for every ~10 seconds of code execution will be auto-terminated. Most scripts should spend most of their time yielding.
ZallCaTor #3
Posted 03 November 2015 - 08:10 AM
Oh ok. I see, before I used an "while" loop, but not in combination with a true/false.
I was simply using "while" fallowed by the redstone input string.
Thank you, I think I get it now. I can't test it atm, but I'll comment here tomorrow with an update on whether it worked or not, which I'm sure it will.
Thanks again.

Ok, so the code works, now the problem arises when I want it to do more thatn just send a redstone signal. I want it to also send a rednet message.
so, for example, I want it to send a rednet message "GenOn"/"GenOff" acording to the redstone signal. I could add an "if/else" or "while true do," after "end" however, the computer would never reach that point, as the first "while true do" loop is infinate, as it will always be "true." So, I have to figure out how to splice other commands into the first set of commands. (This is where I got stuck allot in other programs)
I'de give you an example of a code I used, but, I really have no idea how to start doing this.

(Do I have to start a new thread to ask this btw? (I'm new))
ZallCaTor #4
Posted 05 November 2015 - 02:27 AM
Actually nvm, solved it. Thanks again. (sorry for multipost)