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

how do you make a clock?

Started by IsaacTBeast, 16 March 2014 - 01:20 AM
IsaacTBeast #1
Posted 16 March 2014 - 02:20 AM
Hey guys!! how do you make a clock that runs conputercraft?

Here's the code

I want to put the timer on the middle of the desktop.. but how?


--Desktop
--Created By: IsaacTBeast
--Learned By: IsaacTBeast
--Open Source. You copy this code and make it to your ownself if you have my permission ..
--fLib was created by: NDFJay
--I write the code by hand not by copying it to others..
os.loadAPI("/.astro/system/api/fLib")

slc = 0
tBarC=128
local tBartC = 2
textC = 2
backColor= 1
contextX = 0
iConText="File Manager"
iCon="/.astro/system/images/.icon"
iConLink="/Programs/filema"
iCon2="/.astro/system/images/unicon2"
iConText2="Simple Pastebin"
iConLink2="/Programs/pastebinsi"
systemFile="/.astro/system/.kernel/astro.lua"
backGroundC="/.astro/system/images/.background"
--Calling Variables

term.setBackgroundColor(backColor)
term.clear()
local paintutils = setmetatable(
  {
	loadImage = function(path)
	  local image = _G.paintutils.loadImage(path)
	  assert(image,"Attempted to load faulty image "..path.."!")
	  return image
	end
  },
  {
	__index = _G.paintutils
  }
)
--Title Bar
function titleBar()
term.setCursorPos(1,1)
term.setBackgroundColor(tBarC)
term.setTextColor(tBartC)
term.clearLine()
term.setCursorPos(2, 1)
print("[Astro]")
end
function titleBar2()
term.setCursorPos(36,1)
term.setBackgroundColor(tBarC)
term.setTextColor(tBartC)
print("[System Config]")
end
function titleBar3()
term.setCursorPos(1,1)
term.setBackgroundColor(tBarC)
term.setTextColor(tBartC)
term.clearLine()
term.setCursorPos(2,1)
print("[Exit]")
end
function drawDesktop()
  term.setBackgroundColor(backColor)
  term.clear()
  bground = paintutils.loadImage(backGroundC)
  icon = paintutils.loadImage(iCon)
  icon2 = paintutils.loadImage(iCon2)
  paintutils.drawImage(icon2, 2, 12)
  paintutils.drawImage(icon, 2, 3)
  paintutils.drawImage(bground,1,1)
  term.setBackgroundColor(backColor)
  term.setCursorPos(1,9)
  term.setTextColor(colors.red)
  print("+")
  term.setCursorPos(2,10)
  term.setTextColor(128)
  print(iConText)
  term.setTextColor(colors.red)
  term.setCursorPos(1,17)
  print("+")
  term.setTextColor(128)
  term.setCursorPos(2, 18)
  print(iConText2)
  titleBar()
  titleBar2()
end

function drawMenu1()
  term.setCursorPos(1,2)
  print("		  ")
  term.setCursorPos(1,3)
  print(" Shutdown ")
  term.setCursorPos(1,4)
  print(" Restart  ")
  term.setCursorPos(1,5)
  print("		  ")
end
function drawMenu2()
  term.setBackgroundColor(128)
  term.setTextColor(256)
  term.setCursorPos(contextX, contextY)
  print("			 ")
  term.setCursorPos(contextX, contextY+1)
  print("  Terminal   ")
  term.setCursorPos(contextX, contextY+2)
  print(" FileManager ")
  term.setCursorPos(contextX, contextY+3)
  print("			 ")

end
function drawMenu3(iX, iY)
  term.setBackgroundColor(128)
  term.setTextColor(256)
  term.setCursorPos(iX, iY)
  print("		 ")
  term.setCursorPos(iX, iY+1)
  print(" Rename  ")
  term.setCursorPos(iX, iY+2)
  print(" Chan-Icon ")
  term.setCursorPos(iX, iY+3)
  print(" Re-Link ")
  term.setCursorPos(iX, iY+4)
  print("		 ")
end
function drawMenu4()
term.setBackgroundColor(128)
term.setTextColor(256)
term.setCursorPos(36,2)
print("			   ")
term.setCursorPos(36,3)
print(" C-Background  ")
term.setCursorPos(36,4)
print(" Update Astro  ")
term.setCursorPos(36,5)
print("			   ")
end
drawDesktop()
while true do
local event,button, X, Y = os.pullEventRaw("mouse_click")
  if slc == 0 then
	if event == "mouse_click" then
	  if X >= 2 and X <= 8 and Y == 1 and button == 1  then
		drawMenu1()
		slc = 1
		  elseif X >= 2 and X <= 5 and Y >= 3 and Y <= 9 and button == 1 then
		  shell.run(iConLink)		
			elseif X >= 1 and Y >= 2 and button == 2 then slc = 2
			  if  X >=38 then
			  contextX = 38
			  end
			  if Y >=14 then
			  contextY = 14
			  end
			  if X <= 38 then
			  contextX = X
			  end
			  if Y <= 14 then
			  contextY = Y
			  end
			  drawMenu2()
				elseif X == 1 and Y == 9 and button == 1 then slc = 3
				  drawMenu3(1,11)
					elseif X >= 2 and X <= 6 and Y >= 12 and Y <= 15 and button == 1 then
					  shell.run(iConLink2)
						elseif X == 1 and Y == 18 and button == 1 then slc = 3
						  drawMenu3(1,18)
						   elseif X >= 36 and X <= 50 and Y == 1 then slc = 4
							 drawMenu4()
								  
		else	
		drawDesktop()	  
	   end
	  end		  
   elseif slc == 1 then
	 if X >= 1 and X <= 11  and button == 1 and Y == 3 then slc = 0
	   os.shutdown()
	   elseif X >= 1 and X <= 11 and Y == 4 and button == 1 then slc = 0
	   os.reboot()
	   else
	   slc = 0
	   drawDesktop()
  end  
elseif slc == 2 then
	  if X >= contextX and X <= contextX+13 and Y == contextY+1 and button == 1 then slc = 0
		shell.run("/Programs/terminal")
		drawDesktop()
		  elseif X >= contextX and X <= contextX+13 and Y == contextY+2 and button == 1 then slc = 0
			shell.run(iConLink)
			drawDesktop()
			   else
				slc = 0
				drawDesktop()  
			
	   end
	elseif slc == 3 then
	  if X >= 1 and X <= 12 and Y == 12 and button == 1 then
	  term.setTextColor(256)
	  term.setBackgroundColor(backColor)
	  term.setCursorPos(2,10)
	  print("		 ")
	  term.setCursorPos(2,10)
	  input = read()
	  fLib.replaceLine(systemFile,16,'iConText="'..tostring(input)..'"')
	  return
	  shell.run(systemFile)
  
		  elseif X >= 1 and X <= 12 and Y == 13 and button == 1 then
			 term.setBackgroundColor(128)
			 lY = 8
			  for i =1,3 do
			  term.setCursorPos(18, lY)
			  print("					 ")
			  lY = lY+1
			  end
				term.setBackgroundColor(256)
				term.setTextColor(1)
				term.setCursorPos(19, 9)
				print("				   ")
				term.setCursorPos(20,9)
				input = read()
				fLib.replaceLine(systemFile,17,'iCon="'..tostring(input)..'"')
				return
				shell.run(systemFile)
				   elseif X >= 1 and X <= 12 and Y == 14 and button == 1 then
					 term.setBackgroundColor(128)
					   lY = 8
			
					   for i = 1,3 do
					   term.setCursorPos(18,lY)
						print("						")
					   lY = lY+1
					   end
					   term.setBackgroundColor(256)
					   term.setCursorPos(19, 9)
					   print("					  ")
					 term.setCursorPos(20,9)
					  term.setTextColor(1)
					  input = read()
					 fLib.replaceLine(systemFile, 18,'iConLink="'..tostring(input)..'"')
					 return
					 shell.run(systemFile)
				
				
							  
				else
				slc = 0
				drawDesktop()
			   end
				 elseif slc == 4 then
					if X >= 36 and X <= 50 and Y == 3 and button == 1 then
					   term.setBackgroundColor(128)
						 lY = 8
						
						 for i = 1, 3 do
						 term.setCursorPos(18,lY)
						 print("						 ")
						 lY = lY+1
						 end
						 term.setBackgroundColor(256)
						 term.setCursorPos(19,9)
						 print("					   ")
						 term.setCursorPos(20,9)
						 term.setTextColor(1)
						 input = read()
						 fLib.replaceLine(systemFile,23, 'backGroundC= "'..tostring(input)..'"')
	   return
	   shell.run(systemFile)
	   elseif X >= 36 and X <= 50 and Y == 4 and button == 1 then
			
	   term.setBackgroundColor(128)
	   lY = 8
	   for i = 1, 3 do
		  term.setCursorPos(18,lY)
		  print("					  ")
	   end
	   term.setCursorPos(20,9)
	   term.setTextColor(1)
	   print("  Updating Astro OS   ")	
	   while true do
														   local source = http.get("http://pastebin.com/raw.php?i=PMP5KhJm")
		  local update = fs.open("/.astro/system/.kernel/astro.lua", "w")
		  update.write(source.readAll())
		  update.close()
		  sleep(1)
		  os.reboot()
	   end
			
				
	  
	  
						 else
						 slc = 0
						 drawDesktop()
			  end
		
  
			

		end
  
	 end
Edited on 17 March 2014 - 05:25 AM
oeed #2
Posted 16 March 2014 - 02:27 AM
You need to stop asking how do I do everything. People don't want to and will not do everything for you. You don't even try looking, it's starting to annoy me and numerous other users. Try to do things your self. If you tried and have an error that you can't fix then we'll help you, but make sure you've actually got some code to show.
SuicidalSTDz #3
Posted 16 March 2014 - 02:35 AM
I don't think clocks can run computercraft. You may want to rephrase the question.
theoriginalbit #4
Posted 16 March 2014 - 02:43 AM
Just gonna leave this here.
IsaacTBeast #5
Posted 16 March 2014 - 02:47 AM
Ok.. I hope I can do this alone very soon.. I update my OS with something very special.
SuicidalSTDz #6
Posted 16 March 2014 - 03:00 AM
Why not start small with a simple game and work your way up. Just a thought.
IsaacTBeast #7
Posted 16 March 2014 - 03:07 AM
Maybe mate.
TheOddByte #8
Posted 16 March 2014 - 12:48 PM
Do you have any code to post at all? Since we are not here to create it for you! :P/>
And if you're new to programming or Lua then I suggest you read tutorials, read through other peoples code to see if you can learn from it and just mess around with alot of code until
you feel that you've got a hang of it, Don't ask other people for help before you've tried it yourself! ;)/>

Offtopic: Also, You're locations says: I'am inside your brian it should be I'm inside your brian or I am inside your brian + I'm pretty sure it should be brain and not brian( am I correct? )