Follow the comments, report the bugs.
Spoiler
term.redirect(peripheral.wrap("back"))
local image = paintutils.loadImage("saver")
local screenSaver = false
local screenSaverTriggerTime = 120
-- initialize the program here (yup, your code here)
-- set up the first trigger for the screensaver (2 minutes)
local screenSaverTrigger = os.startTimer(screenSaverTriggerTime)
while true do
local eventData = {os.pullEventRaw()}
-- change this to os.pullEvent if you want this program to be... terminatable
-- keep in mind that now all the event data is in a table;
-- so the event name is eventData[1], first variable is eventData[2], etc.
if eventData[1] == "timer" and eventData[2] == screenSaverTrigger then
paintutils.drawImage(image, 15, 2) -- whatever that prints the screensaver
screenSaver = true
else
-- this else branch will turn off the screensaver when any
-- other event fires apart from the one that turns it on
if screenSaver then
-- redraw the whole control panel
-- (I prefer calling a function here that does that)
screenSaver = false
-- set the trigger up again
screenSaverTrigger = os.startTimer(screenSaverTriggerTime)
end
end
-- process eventData here (yup, your code here)
end
I'll be real honest here, I barely understand what exactly is going on so I can only thank you for this, but I don't quite understand it, as much comments as you wrote, is there any way to explain it in an easier way? :P/> (Sorry I'm not a LUA pro :P/>)
What my idea is of whats going on (As far as I understand it):
-Declare some variables for the timer & image
-Start the counter for the screensaver
-Wait for an event > Put the event in a table for easy usage
-If the event that happens is the timer finishing, it puts up the screensaver & goes back to the start
-If the event is not the timer finishing, it checks if the screensaver is up, if yes, then it prints the menu with all the things that happen in there & take down the screensaver
-Restarts the timer
And from this part I dont get what you mean with "process eventData here".
I might be completely wrong, sorry if that is the case :P/>
I still don't get how in this thing, it waits for a monitor_touch event WHILE the screensaver counter is going (as in, the menu is up, screensaver is off, it waits for a touch event, and aborts this if the timer hits 0), or is the fact that when the timer triggers, it reads it as an event, and replies to that by putting up the screensaver and restarting the while loop?