So I've got 2 functions that work fine seperetaly, but I cant figure out how to combine them properly.
The first function displays the time on the screen and gets updated every second.
function clock()
clock = true
while clock do
term.clear()
term.setCursorPos(10,6)
local time = os.time()
time = textutils.formatTime(time, true)
print('The time is: '..time)
os.sleep(1)
break
end
end
The second function disables the clock when enter is pressed.
function keyread()
while true do
local sEvent, param = os.pullEvent('key')
if sEvent == 'key' then
if param == 28 then
clock = false
term.clear()
term.setCursorPos(10,6)
print('Clock stopped')
term.restore()
end
end
end
end
I've tried quite a few things and this is the closest I've been to make it work.
Here, the time is shown, but only gets updated when any key is pressed. Enter stops the clock as intended.
clock = true
while true do
local sEvent, param = os.pullEvent('key')
if sEvent == 'key' then
if param == 28 then
clock = false
term.clear()
term.setCursorPos(10,6)
print('Clock stopped')
term.restore()
break
else
while clock do
term.clear()
term.setCursorPos(10,6)
local time = os.time()
time = textutils.formatTime(time, true)
print('The time is: '..time)
os.sleep(1)
break
end
end
end
end
Any help is much appreciated :)/>