This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
DeGariless's profile picture

Making a menu that can timeout

Started by DeGariless, 26 April 2014 - 02:31 AM
DeGariless #1
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?
Bomb Bloke #2
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
DeGariless #3
Posted 26 April 2014 - 09:47 AM
Thank you! I'll mess around with this bit of code to learn how it works. :)/>