33 posts
Location
Area51,Nevada,USA
Posted 07 September 2013 - 11:55 AM
Startup Code
shell.run("monitor","right","clock")
Clock Code
term.clear()
term.setCursorPos(1,1)
z=true
while true do
shell.run"time"
sleep(0.75)
term.setCursorPos(1,1)
term.clear()
end
this is a pretty good clock and it auto-updates its self when you log off and back on
515 posts
Location
Australia
Posted 07 September 2013 - 01:15 PM
Although (No offence) this program is practically completely useless, you could improve it by removing some of the clutter.
while true do term.clear() term.setCursorPos(1,1) shell.run("/rom/programs/time") sleep(0.75) end
107 posts
Posted 09 September 2013 - 09:30 AM
Also why is z even declared? I can't see where you use it.
331 posts
Posted 09 September 2013 - 10:49 AM
just a pointer, you could do
while true do
term.redirect(peripheral.wrap(side))
shell.run("clear")
shell.run("time")
sleep(1)
end
Edit: Why do you declare z and call term.clear and term.setCursorPos at the start why not move them to the top of your while loop
8543 posts
Posted 09 September 2013 - 11:32 AM
Don't put a redirect in a while loop without balancing it with a restore.
107 posts
Posted 09 September 2013 - 01:31 PM
It WOULD be pretty funny to see someone trying to debug that one… "I've run term.restore() 500 times and it's STILL stuck on the monitor!"
7508 posts
Location
Australia
Posted 09 September 2013 - 02:23 PM
It WOULD be pretty funny to see someone trying to debug that one… "I've run term.restore() 500 times and it's STILL stuck on the monitor!"
There was a thread in AaP about that I little while ago that I helped with, multiple redirects but only one restore. One of my old programs also had that edge case where it would occasionally get stuck on a monitor too.
2 posts
Location
New York
Posted 16 September 2013 - 11:06 PM
I wrote a pretty simple clock program free for anyone to use, please give comments on where i can reduce code.
local time = os.time()
local moniter = peripheral.wrap('side')
local function getTime()
moniter.clear()
moniter.setCursorPos(1, 1)
moniter.write(textutils.formatTime(time, bTwentyFourHour))
sleep(0.75)
end
while true do
getTime()
end
331 posts
Posted 17 September 2013 - 02:15 AM
errr getTime is just writing the same thing over and over move time = os.time() into your function
2 posts
Location
New York
Posted 17 September 2013 - 03:57 AM
so something like this?
local moniter = peripheral.wrap('side')
local function getTime()
time = os.time()
moniter.clear()
moniter.setCursorPos(1, 1)
moniter.write(textutils.formatTime(time, bTwentyFourHour))
sleep(0.75)
end
while true do
getTime()
end
30 posts
Posted 18 September 2013 - 12:00 PM
Hello guys, here is my attempt to code another clock program.
Please tell me what you think about since I'm kind of new to lua therefore any advice/criticism is welcome.
function showTime (display)
display = display or term
while true do
local timer = os.startTimer(1)
local event, id = os.pullEvent("timer")
if id == timer then
display.clear()
display.setCursorPos(1, 1)
display.write(textutils.formatTime(os.time(), true))
end
end
end
195 posts
Location
Cambridgeshire, England
Posted 24 December 2013 - 12:42 PM
I know this is an old thread but this was my attempt at a clock for a single monitor, no terminal redirects either.</p>
side = ...
print(side)
mon = peripheral.wrap(side)
mon.clear()
while true do
os.startTimer(1)
local event = os.pullEvent("timer")
mon.clear()
mon.setCursorPos(1,3)
mon.write(textutils.formatTime(os.time()),true)
end
I just saved that as clock, called it with &quot;clock top&quot; and it runs on the top monitor. Presumably would work with network attached monitor too
EDIT: Anyone else had issues with the comments suddenly deciding to be posted as plain text HTML?
Edited on 24 December 2013 - 02:33 PM
1 posts
Posted 18 March 2014 - 11:58 PM
Like 6677, I know this is an old thread but I've made my own clock for my server spawn and I'm happy to share it with you :)/>
m = peripheral.wrap("side")
m.clear()
m.setTextScale(2)
m.setTextColor(colors.red)
function updateClock(m)
while true do
mcT = os.time()
m.setCursorPos(1,5)
m.clearLine()
m.setCursorPos(6,5)
m.write(textutils.formatTime(mcT))
m.setCursorPos(1,2)
m.clearLine()
m.setCursorPos(3,2)
m.write("Jour "..os.day())
sleep(0.1)
end
end
updateClock(m)
Just in case, you need to replace "side" at lign 1 by the side where your monitor is AND you need to have Advanced stuffs (Computer, Monitor)
PS: I use a 3x2 monitor but you can have a smaller one or a bigger one, just check for "text size" at lign 3, "text color" at lign 4 and "text placment" at lign 10 and 14 :)/>