7 posts
Posted 31 March 2014 - 04:20 PM
I am trying to figure out how to do something if a monitor hasn't been touched in X mins/seconds. For example a screensaver where if you don't touch the screen for 5 mins then it runs a screensaver program, then as soon as you touch the screen again it pulls back up your program.
1281 posts
Posted 31 March 2014 - 04:29 PM
Should be farily straightforward using events and the parallel api
local timerId = os.startTimer(300) --start the timer
while true do
local tEvent = {os.pullEvent()} --get events
if tEvent[1] == "timer" then
if tEvent[2] == timerId then --our timer has elapsed
parallel.waitForAny( --wait for any of the following functions to finish
function()
os.pullEvent"monitor_touch" --this function ends if a monitor touch is detected
end,
function()
while true do --never ending
--screensaver here
end
end
)
timerId = os.startTimer(300) --restart the timer
end
else --something other than the timer happened
timerId = os.starTimer(300) --restart the timer
--other functionailty here
end
end
7 posts
Posted 31 March 2014 - 04:46 PM
Thank you very much, im planning on using
http://pastebin.com/KQjmtASU matrix screensaver then just having a standard program for controlling my auto spawner. Could i just use shell.run("matrix") for the screensaver? then just use error() to quit that program and start my mob spawner program? Or would it be easier to just combine all of that into one program
1281 posts
Posted 31 March 2014 - 05:42 PM
Throwing shell.run("whatever program") in where it says "–screensaver here" should work just fine. However, im guessing you don't know how the parallel api works, so i suggest atleast having a look at it. It's good to know
http://computercraft.info/wiki/index.php?title=Parallel_%28API%29