8 posts
Location
California, USA
Posted 26 April 2014 - 04:31 AM
Hello expert computercrafters! I'm attempting to make a program that can display a menu, ask for user input, and automatically shutdown the computer if no choice is made within x amount of time. Is this possible? How?
7083 posts
Location
Tasmania (AU)
Posted 26 April 2014 - 09:20 AM
It's indeed possible, but difficult to know how much explanation to give you without seeing your current progress.
The basic way to go about it is to set timers, then listen for key / timer events. Something along these lines:
local myTimer = os.startTimer(5)
while true do
local myEvent = {os.pullEvent()}
if myEvent[1] == "timer" and myEvent[2] == myTimer then
print("Time's up! shutting down...")
sleep(3)
os.shutdown()
elseif myEvent[1] == "key" and myEvent[2] == keys.down then
(move down the menu)
elseif ...
etc...
end
end
8 posts
Location
California, USA
Posted 26 April 2014 - 09:47 AM
Thank you! I'll mess around with this bit of code to learn how it works. :)/>