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

Timer: the first program you should make!

Started by GamerNebulae, 12 January 2013 - 06:31 AM
GamerNebulae #1
Posted 12 January 2013 - 07:31 AM
Needed for this program: Computer (Advanced is optional), Monitor (Advanced is optional)


  local s = 0
  local m = 0
  local h = 0
  mon = peripheral.wrap("top")

while true do  
  s = s + 1
  sleep(1)
	if s > 59 then
	  s = 0
	  m = m + 1
	end
	if m > 59 then
	  m = 0
	  h = h + 1
	end
  mon.clear()
  mon.setCursorPos(1,1)
  mon.write("Time: "..h..":"..m..":"..s)
end

What it does (you can change the "mon.write" to print) is it counts to 60 (variable s), then it adds 1 to the minutes (variable "m"), and when it reaches 60 minutes it counts 1 to the hours (variable h).

I made this simple program to use in my advanced Industrial Centrifuge/Electrolyzer room. If you have requests/tips, please send 'em in!

Greetings,

GamerNebulae (Ivo)
anonimo182 #2
Posted 12 January 2013 - 07:56 AM
Good for a 1 post