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

Redstone Status Indicator Troubleshooting

Started by beckadd, 14 March 2018 - 11:55 PM
beckadd #1
Posted 15 March 2018 - 12:55 AM
So just to preface this post, I'm super new to ComputerCraft (I started yesterday), so what you're about to see is probably something you'll look at and go "well right here it's wrong, obviously." Anyways, I'm trying to make a looped program that displays the current status of a machine that outputs a redstone signal when active and have that program only "run" if an "on/off" switch is also on. However, the status does not refresh when I tested the program using redstone torches. What do I have wrong?


local signal = rs.getInput("left")
local on_off = rs.getInput("right")
while on_off == true do
while signal ~= true do
  print("The CGA is currently off.")
  sleep(0.5)
  term.clear()
  term.setCursorPos(1,1)
end
while signal == true do
  print("The CGA is currently on.")
  sleep(0.5)
  term.clear()
  term.setCursorPos(1,1)
end
end
Bomb Bloke #2
Posted 15 March 2018 - 01:47 AM
local signal = rs.getInput("left")

This stores the state of the left input in "signal", as of the time the line is processed. "signal" will retain that value regardless as to whether the left input changes or not. If you always want fresh data, then you need to re-call rs.getInput("left").

I suggest:

while rs.getInput("right") do
	if rs.getInput("left") then
		print("The CGA is currently on.")
	else
		print("The CGA is currently off.")
	end
	
	os.pullEvent("redstone")  --# Yield (wait) until a redstone state change occurs.

	term.clear()
	term.setCursorPos(1,1)
end