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

[LUA][Question] Loop Code, Why isn't this working?

Started by PoisonMondo, 13 October 2012 - 04:54 AM
PoisonMondo #1
Posted 13 October 2012 - 06:54 AM
Ive been trying to loop the code below so it refreshes on the screen. The problem is the code just freezes and doesn't update. I have looked around and i cant understand why it isn't working. My current code is below


-- Reactor control: Turn off reactor
rout = colors.combine(rout,colors.red)
rs.setBundledOutput("bottom",rout)
-- Make sure input is intialised
rin=rs.getBundledInput("bottom")
mon = peripheral.wrap('top')
mon.setTextScale(1)
i = 1
while i  <= 5 do
	mon.clear()
	mon.setCursorPos(3,1)
	mon.write("========POISONSYS REACTOR=========")
	mon.setCursorPos(3,2)
	mon.write("=======CONTROL SYSTEM V1.0========")
	if(colors.test(rout,colors.red)) then
	mon.setCursorPos(1,4)
	mon.write("Reactor is  : OFFLINE")
	else
	mon.setCursorPos(1,4)
	mon.write("Reactor is  : ONLINE")
	end
	if(colors.test(rin,colors.black)) then
	mon.setCursorPos(1,6)
	mon.write("Wtr_cooling is  : ONLINE")
	else
	mon.setCursorPos(1,6)
	mon.write("Wtr_cooling is  : OFFLINE")
	end
	if(colors.test(rin,colors.green)) then
	mon.setCursorPos(1,8)
	mon.write("Ice_cooling is  : ONLINE")
	else
	mon.setCursorPos(1,8)
	mon.write("Ice_cooling is  : OFFLINE")
	end
	i = i + 1
	sleep(2)
  
end
Lyqyd #2
Posted 13 October 2012 - 06:57 AM
Well, your code does have it limited to five refreshes two seconds apart. Why did you include that if you want it to continually refresh?
PoisonMondo #3
Posted 13 October 2012 - 07:39 AM
that was just part of a test, and it wasnt refreshing at all.
Luanub #4
Posted 13 October 2012 - 07:47 AM
I don't see anything that would keep it from updating. I'll try it when I get home and see if it behaves the same for me.

One bit of advice though, instead of using colors.test use rs.testBundledInput. It seems to be less error prone

--replace stuff like:
if(colors.test(rin,colors.green)) then
--with
if rs.testBundledInput("bottom", colors.green) then

I've seen quite a few people on here that have had weird issues using the colors.test method.
PoisonMondo #5
Posted 13 October 2012 - 07:47 AM
ok ill try that, thanks
PoisonMondo #6
Posted 13 October 2012 - 08:21 AM
It works, if anyone wnats to use the updated code, here it is.

[CODE]
-- Coded by PoisonMondo &amp; Help from community
-- Reactor control: Turn on Reactor
rout = colors.subtract(rout,colors.red)
rs.setBundledOutput("back",rout)
-- Make sure input is intialised
rin=rs.getBundledInput("bottom")
mon = peripheral.wrap('top')
mon.setTextScale(1)
i = 1
while i  <= 31551 do
mon.clear()
mon.setCursorPos(3,1)
mon.write("========POISONSYS REACTOR=========")
mon.setCursorPos(3,2)
mon.write("=======CONTROL SYSTEM V1.0========")
if rs.testBundledInput("bottom", colors.red) then
mon.setCursorPos(1,4)
mon.write("Reactor is  : OFFLINE")
else
mon.setCursorPos(1,4)
mon.write("Reactor is  : ONLINE")
end
if rs.testBundledInput("bottom", colors.black) then
mon.setCursorPos(1,6)
mon.write("Wtr_cooling is  : ONLINE")
else
mon.setCursorPos(1,6)
mon.write("Wtr_cooling is  : OFFLINE")
end
if rs.testBundledInput("bottom", colors.green) then
mon.setCursorPos(1,8)
mon.write("Ice_cooling is  : ONLINE")
else
mon.setCursorPos(1,8)
mon.write("Ice_cooling is  : OFFLINE")
end
if rs.testBundledInput("bottom", colors.orange) then
mon.setCursorPos(1,10)
mon.write("Reactor Meltdown: True")
rout = colors.combine(rout,colors.red)
rs.setBundledOutput("back",rout)
else
mon.setCursorPos(1,10)
mon.write("Reactor Meltdown: False")
rout = colors.subtract(rout,colors.red)
rs.setBundledOutput("back",rout)
end
i = i + 1
sleep(3)
end