I have a problem!
I'm trying to make a program that prints the time and a button to exit it.
I can run the program but the button won't do anything.
Heres my code:
Spoiler
What am I doing wrong?
Posted 09 April 2013 - 11:11 PM
Posted 09 April 2013 - 11:53 PM
function main()
term.clear()
term.setBackgroundColor(1)
term.setTextColor(32768)
term.clear()
term.setCursorPos(1,1)
print("The time is: ")
term.setCursorPos(1,3)
print(textutils.formatTime(os.time(), true))
term.setCursorPos(1,5)
print("[Exit]")
slc = 0
sleep(1)
end
main()
while true do
event, button, x, y = os.pullEvent("mouse_click")
if event == "mouse_click" then
if slc == 0 then
if x >= 1 and x <= 6 and y == 5 and button == 1 then
term.clear()
term.setCursorPos(1,1)
print("Exited!")
sleep(5)
os.reboot()
else
main()
end
end
end
end
Posted 10 April 2013 - 12:08 AM
Posted 10 April 2013 - 03:49 AM
function main()
while true do
term.clear()
term.setBackgroundColor(1)
term.setTextColor(32768)
term.clear()
term.setCursorPos(1,1)
print("The time is: ")
term.setCursorPos(1,3)
print(textutils.formatTime(os.time(), true))
term.setCursorPos(1,5)
print("[Exit]")
slc = 0
sleep(1)
end
end
function catchmouse()
event, button, x, y = os.pullEvent("mouse_click")
if event == "mouse_click" then
if slc == 0 then
if x >= 1 and x <= 6 and y == 5 and button == 1 then
term.clear()
term.setCursorPos(1,1)
print("Exited!")
sleep(5)
os.reboot()
else
main()
end
end
end
end
while true do
parallel.waitForAny(main, catchmouse)
end
Posted 10 April 2013 - 04:23 AM
0 members, 1 guests, 0 anonymous users