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

Redstone Detection

Started by NOOB CODER, 30 October 2012 - 06:39 AM
NOOB CODER #1
Posted 30 October 2012 - 07:39 AM
This is my first post so if i do something wrong dont be hard on me

Hi i'm new to the mod and have just used basic coding but i wanted to have my monitors to say Solar Arrays offline but when there is a redstone signal sent to the computer it says Solar Arrays Online and when the signal stops the Status goes back to Offline.
I know how to do most of the code but if someone could tell me the code to detect a redstone signal and the basic coding that would really help me out

Thanks :P/>/>
Luanub #2
Posted 30 October 2012 - 07:50 AM
Here's a example of what you will want to do.

local e,p1 = os.pullEvent("redstone")
if rs.getInput("changeToTheSideYouWantToMonitor") then
  --array is online
else
  --array is offline
end
KaoS #3
Posted 30 October 2012 - 07:53 AM
well the command rs.getInput(side) returns true if there is a signal on the side and false if the redstone is off so basically


local side='back'
if rs.getInput(side) then
  print('solar panels are on')
else
  print('solar panels are off')
end

now that will only check once though so we want to have a loop to keep doing it so just put it in a while true loop. then we just have to make it sleep until an event occurs so it doesn't keep looping at super speed. this can be done with os.pullEvent('redstone') - this command waits for an event, in this case a redstone event. when redstone changes next to this computer the command will complete and return some values that we don't need right now. final code (without monitor functionality, I'm sure you know that)


while true do
  os.pullEvent('redstone')
  if rs.getInput('back') then
	print('solar panels are on')
  else
	print('solar panels are off')
  end
end

EDIT: damn ninjas