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

Need help with a clock

Started by darkreaper_44, 20 November 2012 - 12:02 PM
darkreaper_44 #1
Posted 20 November 2012 - 01:02 PM
ok so what i have thus far is:


do
local t = textutils.formatTime(os.time())
local x,y = term.getSize()
x = x - string.len(t) + 1
term.setCursorPos(x,y)
term.write(t)
end


With that i get the real server time where it is ran. It is in Super small print and i would
like to make it larger print, and also minecraft time.

The monitor size is 3 high 7 long and its on the back of the computer.


I would also like it to run on computer startup so please help me :/
Kingdaro #2
Posted 20 November 2012 - 01:43 PM
This is what the peripherals API is for! :(/>/>


local monitor = peripheral.wrap('back')
monitor.setTextScale(3) -- can be any value from 0.5 to 5, experiment and see what fits.

while true do
  local t = textutils.formatTime(os.time())
  local x,y = monitor.getSize()
  x = x - string.len(t) + 1
  monitor.setCursorPos(x,y)
  monitor.write(t)

  sleep(0.5)
end

Went ahead and put it in a loop so it doesn't print the time just once.
darkreaper_44 #3
Posted 20 November 2012 - 02:18 PM
This is what the peripherals API is for! :(/>/>


local monitor = peripheral.wrap('back')
monitor.setTextScale(3) -- can be any value from 0.5 to 5, experiment and see what fits.

while true do
  local t = textutils.formatTime(os.time())
  local x,y = monitor.getSize()
  x = x - string.len(t) + 1
  monitor.setCursorPos(x,y)
  monitor.write(t)

  sleep(0.5)
end

Went ahead and put it in a loop so it doesn't print the time just once.

I did this and im getting nil it reads


clock:6: attempt to call nil
darkreaper_44 #4
Posted 20 November 2012 - 02:32 PM
Some one please help im tired of getting error after error lol

here is my clock code it appears in a bottom corner.


local monitor = peripheral.wrap('back')
monitor.setTextScale(3) -- can be any value from 0.5 to 5, experiment and see what fits.
while true do
  local t = textutils.formatTime(os.time())
  local x,y = monitor.getSize()
  x = x - string.len(t) + 1
  monitor.setCursorPos(x,y)
  monitor.write(t)
  sleep(0.5)
end


please help me center it :/
Lyqyd #5
Posted 20 November 2012 - 02:47 PM
Did you copy and paste exactly that code? If you retyped it, you may have accidentally introduced a typo.

Edit: Try to stick to just one topic for continuing help on one piece of code.
cmurtheepic #6
Posted 20 November 2012 - 02:55 PM
well first you have to change the programs name to run on startup :(/>/>
remiX #7
Posted 21 November 2012 - 02:15 AM
To center you take the width - length of text then divide that by 2.

local monitor = peripheral.wrap('right')
monitor.setTextScale(1) -- can be any value from 0.5 to 5, experiment and see what fits.
while true do
  local t = textutils.formatTime(os.time(), false)
  local x,y = monitor.getSize()
  monitor.setCursorPos((x - #t)/2,2)
  monitor.write(t)
  sleep(0.5)
end

Setting the scale of the text bigger than 1 will mess it up, because the length of the text doesn't change. If you make the scale more than 1, you will have to find the center point manually.