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

[Lua][Question] A good Loop and Monitor

Started by Uchiha Madara, 28 June 2012 - 03:45 PM
Uchiha Madara #1
Posted 28 June 2012 - 05:45 PM
I need help making a good loop to check if a signal is on or off and display on a 2x3 monitor
i have the signal part but need help with the loop and how to show on monitor without running the monitor program.
MysticT #2
Posted 28 June 2012 - 05:49 PM
You mean a redstone signal?
This should work:

local sSide = "left" -- the side the monitor is on

-- check if monitor is present
if peripheral.isPresent(sSide) and peripheral.getType(sSide) == "monitor" then
  -- redirect terminal output to the monitor
  term.redirect(peripheral.wrap(sSide))
else
  -- no monitor, exit
  print("No monitor found")
  return
end

-- loop
while true do
  -- print here
  -- if you want to exit the program, use break to stop the loop
  -- wait for redstone change
  os.pullEvent("redstone")
end

-- restore terminal output
term.restore()
Uchiha Madara #3
Posted 28 June 2012 - 07:19 PM
ok… still need help trying to make it with bundled cables connected to mfes i have one mfe set to output on empty and one seet to output on full
the one set to empty has a red cable and the on set to full has a green cable how can i display like : MFE 1# is: Not empty/Empty, MFE 2# is: Full/Not Full
MysticT #4
Posted 28 June 2012 - 07:39 PM

local monitorSide = "left" -- the side the monitor is on
local cableSide = "back" -- the side the bundled cable is on

-- check if monitor is present
if peripheral.isPresent(monitorSide) and peripheral.getType(monitorSide) == "monitor" then
  -- redirect terminal output to the monitor
  term.redirect(peripheral.wrap(monitorSide))
else
  -- no monitor, exit
  print("No monitor found")
  return
end

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

-- loop
while true do
  -- clear screen
  clear()
  -- test each input
  write("MFSU#1: ")
  if rs.testBundledInput(cableSide, colors.red) then
	print("Empty")
  else
	print("Not Empty")
  end
  write("MFSU#2: ")
  if rs.testBundledInput(cableSide, colors.green) then
	print("Full")
  else
	print("Not Full")
  end
  -- wait for redstone change
  os.pullEvent("redstone")
end

-- restore terminal output
term.restore()