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

Monitor Clock

Started by jacobc436, 24 July 2012 - 09:31 PM
jacobc436 #1
Posted 24 July 2012 - 11:31 PM
I got into Lua coding about a day ago, and I want to make a digital clock that will update once every second. As of right now, I have the following.


a = ("1")
b = ("2")
c = ("3")
d = ("4")
e = ("5")
f = ("6")
g = ("7")
h = ("8")
i = ("9")
j = ("0")
funtion mainLoop()
    while(true) do
yourmon = peripheral.wrap("left")
yourmon.setTextScale(5)
term.redirect(yourmon)
print("Test")
term.restore()

I put the 'while(true) do' so that, from what I saw in other scripts, it would loop the next lines of code. But I don't know where to go from here, and any help would be greatly appreciated. The screen size is, at the moment, 4 wide and 3 tall.
Noodle #2
Posted 25 July 2012 - 09:54 AM
Its: while true do - You don't need "( )"
a = ("1")
b = ("2")
c = ("3")
d = ("4")
e = ("5")
f = ("6")
g = ("7")
h = ("8")
i = ("9")
j = ("0")
funtion mainLoop()
  while true do
    yourmon = peripheral.wrap("left")
    yourmon.setTextScale(5)
    term.redirect(yourmon)
    print("Test")
    term.restore()
  end
end
mainLoop()
This code will print TEST about a million times on your monitor at 5 text size, if it doesn't break first.
Cranium #3
Posted 29 July 2012 - 03:59 PM
I don't understand how this would be a clock though…
djblocksaway #4
Posted 29 July 2012 - 05:03 PM
while true do
shell.run("time")
sleep(0.5)
end

Try that?
Patistar #5
Posted 29 July 2012 - 05:16 PM
Without any sleep() command the program will normally end with an error..
Pugz #6
Posted 29 July 2012 - 08:58 PM
Hey, just thought I would post what I did, I'm far from a pro but it works as intended :)/>/>


---[[ variables
monitor = peripheral.wrap("left")
--]]

---[[ clock
while true do
  term.redirect(monitor)
  monitor.clear()
  term.setCursorPos(1,1)
  monitor.setTextScale(3)
  shell.run("time")
  sleep(1)
  term.restore()
end
--]]

You can run the program by simply typing in clock to the console or you can edit your startup program to use shell.run("clock"). This is only the server time though but it will update every second and keep to the top left of the screen. Also you need to make sure that you change the
monitor = peripheral.wrap("left") change the left to whatever side your monitor is on.

again I'm a nab but I did this one myself the other day, hope it helps! :ph34r:/>/>