Posted 07 November 2016 - 01:30 AM
Hi,
I am new to posting on the forums. I have a question, and while I have looked for an answer, both on the wiki and here, I am not sure where to find an answer.
I am hoping I can get a little help.
Here is what I'm trying to do:
I have a computer putting off a redstone signal; 40 seconds on, 20 seconds off. It is outputting to a monitor, showing how much time remains on the present status. So far, so good.
Now, I would like to be able to press any key and stop the program, preferably putting a notice on the monitor that the system is not running.
I have looked up using os.pullEvent(), however since I am using pause(1) in my program, it does not appear to work.
Any suggestions?
Present code: function timer is working.
local monitor = peripheral.wrap("top")
term.clear()
term.setCursorPos(1,1)
while true do
rs.setOutput("bottom",true)
monitor.clear()
monitor.setCursorPos(2,1)
monitor.write("Spawn")
monitor.setCursorPos(1,4)
monitor.write("Seconds")
for x = 40 , 1 , -1 do
monitor.setCursorPos(3,3)
if x>9 then
monitor.write(tostring(x))
else
monitor.write(" ")
monitor.write(tostring(x))
end
sleep(1)
end
rs.setOutput("bottom",false)
monitor.clear()
monitor.setCursorPos(2,1)
monitor.write("Clear")
monitor.setCursorPos(1,4)
monitor.write("Seconds")
for x = 20 , 1, -1 do
monitor.setCursorPos(3,3)
if x>9 then
monitor.write(tostring(x))
else
monitor.write(" ")
monitor.write(tostring(x))
end
sleep(1)
end
end
end
function stop()
while true do
e = os.pullEvent("key")
if e == "key" then
return
end
end
end
parallel.waitForAny(timer(),stop())
I am new to posting on the forums. I have a question, and while I have looked for an answer, both on the wiki and here, I am not sure where to find an answer.
I am hoping I can get a little help.
Here is what I'm trying to do:
I have a computer putting off a redstone signal; 40 seconds on, 20 seconds off. It is outputting to a monitor, showing how much time remains on the present status. So far, so good.
Now, I would like to be able to press any key and stop the program, preferably putting a notice on the monitor that the system is not running.
I have looked up using os.pullEvent(), however since I am using pause(1) in my program, it does not appear to work.
Any suggestions?
Present code: function timer is working.
Spoiler
function timer()local monitor = peripheral.wrap("top")
term.clear()
term.setCursorPos(1,1)
while true do
rs.setOutput("bottom",true)
monitor.clear()
monitor.setCursorPos(2,1)
monitor.write("Spawn")
monitor.setCursorPos(1,4)
monitor.write("Seconds")
for x = 40 , 1 , -1 do
monitor.setCursorPos(3,3)
if x>9 then
monitor.write(tostring(x))
else
monitor.write(" ")
monitor.write(tostring(x))
end
sleep(1)
end
rs.setOutput("bottom",false)
monitor.clear()
monitor.setCursorPos(2,1)
monitor.write("Clear")
monitor.setCursorPos(1,4)
monitor.write("Seconds")
for x = 20 , 1, -1 do
monitor.setCursorPos(3,3)
if x>9 then
monitor.write(tostring(x))
else
monitor.write(" ")
monitor.write(tostring(x))
end
sleep(1)
end
end
end
function stop()
while true do
e = os.pullEvent("key")
if e == "key" then
return
end
end
end
parallel.waitForAny(timer(),stop())