Posted 20 August 2013 - 05:19 PM
Hey folks, I'm writing a basic timer that can be controlled with two factors: If redstone is off, the timer is running. If redstone is on, the timer is stopped. I want to implement something that will allow me to toggle it on/off using the touchscreen, but I can't find anything that won't pause the script until it gets input. Any help is greatly appreciated :)/>. Here's my script: (or look on Pastebin for easier viewing)
timerActive = true
seconds = 0
minutes = 0
hours = 0
days = 0
local monitor = peripheral.wrap("right")
function drawColor(color,x,y)
monitor.setBackgroundColor(color)
monitor.setCursorPos(x,y)
monitor.clearLine()
end
function printMiddle(text, lineNum)
width, height = monitor.getSize()
stringLength = string.len(text)
startPos = math.floor(width/2) - math.floor(stringLength/2) + 1
monitor.setCursorPos(startPos,lineNum)
monitor.write(text)
end
function clearScreen()
monitor.setBackgroundColor(32768)
monitor.clear()
end
-------------
while true do
-------------
signalActive = rs.getInput("left")
timeString = ""..tostring(days).. "d "..tostring(hours).."h "..tostring(minutes).. "m "..tostring(seconds).."s "
--[[ Time Handling ]]--
if seconds == 59 then
seconds = 0
minutes = minutes + 1
end
if minutes == 59 then
minutes = 0
hours = hours + 1
end
if hours == 24 then
hours = 0
days = days + 1
end
--[[ Test for signal or touch and act ]]--
if signalActive then
timerActive = false
else
timerActive = true
end
--[[ timerActive ]]--
if not timerActive then
color = colors.red
monitor.setBackgroundColor(32768)
printMiddle(timeString, 3)
else
color = colors.green
seconds = seconds + 1
monitor.setBackgroundColor(32768)
printMiddle(timeString, 3)
end
--[[ Touchscreen ]]-- This is causing the script to hang :(/>/>
--local event, param1 = os.pullEvent()
--if event == "monitor_touch" then
-- timerActive = not timeActive
--end
--[[ Draw the color ]]--
drawColor(color,1,1)
drawColor(color,1,5)
sleep(1)
clearScreen()
---
end
---