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

Repeat Help.

Started by rlc3xi, 27 February 2013 - 04:29 PM
rlc3xi #1
Posted 27 February 2013 - 05:29 PM
Title: Repeat Help.
I am trying to get my program to keep the display updated with changes in the redstone connecting to it without rebooting the program (if the reactor is on, it says on, when it goes off, it says off). It works for about 3 seconds and the I keep getting the "too long without yielding". Is it possible and if so, is there a better way to do this?


term.clear()
term.setCursorPos(1, 1)
repeat
local mon = peripheral.wrap("top")
local x = rs.getInput("bottom")
local y = rs.getInput("back")
  if x == true then
   mon.setCursorPos(1,2)
   mon.write("																	")
   mon.setCursorPos(1,3)
   mon.write("***Reactor Display Panel***")
   mon.setCursorPos(1,4)
   mon.write("																	")
   mon.setCursorPos(1,5)
   mon.write("-------------------------------------")
   mon.setCursorPos(1,6)
   mon.write("	Reactor Core is OFF")
   mon.setCursorPos(1,7)
   mon.write("-------------------------------------")
  else
   mon.setCursorPos(1,2)
   mon.write("																	")
   mon.setCursorPos(1,3)
   mon.write("***Reactor Display Panel***")
   mon.setCursorPos(1,4)
   mon.write("																	")
   mon.setCursorPos(1,5)
   mon.write("-------------------------------------")
   mon.setCursorPos(1,6)
   mon.write("	 Reactor Core is ON")
   mon.setCursorPos(1,7)
   mon.write("-------------------------------------")
  end
  if y == true then
   mon.setCursorPos(1,8)
   mon.write("	Status:	 OVERHEATING")
   mon.setCursorPos(1,9)
   mon.write("-------------------------------------")
   mon.setCursorPos(1,10)
   mon.write("<><><><><><><><><><><><><><><><><><><>")

  else
   mon.setCursorPos(1,8)
   mon.write("	  Status:   SAFE	  ")
   mon.setCursorPos(1,9)
   mon.write("-------------------------------------")
   mon.setCursorPos(1,10)
   mon.write("<><><><><><><><><><><><><><><><><><><>")
  end
until exit
ChunLing #2
Posted 28 February 2013 - 03:18 AM
You're getting an error because the program continuously updates the monitor, without ever letting any other programs run. You need a pullEvent so that the program only updates when there is a change in the redstone state.

You're also updating a lot of things that end up the same either way, and you rewrap the monitor every loop.

Something like the following should work:
term.clear()
term.setCursorPos(1, 1)
local mon = peripheral.wrap("top")
mon.setCursorPos(1,2)
mon.write("																																  ")
mon.setCursorPos(1,3)
mon.write("***Reactor Display Panel***")
mon.setCursorPos(1,4)
mon.write("																																  ")
mon.setCursorPos(1,5)
mon.write("-------------------------------------")
mon.setCursorPos(1,7)
mon.write("-------------------------------------")
mon.setCursorPos(1,9)
mon.write("-------------------------------------")
mon.setCursorPos(1,10)
mon.write("<><><><><><><><><><><><><><><><><><><>")
while true do
	os.pullEvent("redstone")
	if rs.getInput("bottom") then
		mon.setCursorPos(1,6)
		mon.write("  Reactor Core is OFF")
	else
		mon.setCursorPos(1,6)
		mon.write("   Reactor Core is ON ")
	end
	if rs.getInput("back") then
		mon.setCursorPos(1,8)
		mon.write("  Status:  OVERHEATING")
	else
		mon.setCursorPos(1,8)
		mon.write("	Status:   SAFE		  ")
	end
end

I don't know what the deal is with those really long lines made of spaces. I guess you could cut them, the screen should already be cleared.
Edited on 28 February 2013 - 02:20 AM