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

running clock in a menu

Started by Leon669, 14 April 2015 - 11:38 AM
Leon669 #1
Posted 14 April 2015 - 01:38 PM
Hi I have my desktop and there is a clock (it uses minecraft Time) but i have the problem that it doesnt update without open the file again.

here a part of the code

Spoilerterm.setTextColor(colors.white)
shell.run"cd //"
file = fs.open("loginSettins/curUser", "r")
version = file.readLine()
file.close()
term.setCursorPos(1,1)
print(version)
shell.run"cd //"
shell.run"cd OS"

term.setBackgroundColor(tonumber(farbe))
term.setTextColor(colors.white)
———————————————————————–
local time = os.time()
local formattedTime = textutils.formatTime(time, false)
term.setCursorPos(44,1)
print(formattedTime)
————————————————————————
while true do
local event, button, X, Y = os.pullEvent("mouse_click")
XY = X..","..Y

if XY == "48,17" and button == 1 then
shell.run"clear"
shell.run"dmenu"
end
Edited on 14 April 2015 - 12:28 PM
KingofGamesYami #2
Posted 14 April 2015 - 02:14 PM
To me, it doesn't look like it updates even with a click. Regardless, you'll want to use os.startTimer and the timer event to update your clock.
Leon669 #3
Posted 14 April 2015 - 02:19 PM
To me, it doesn't look like it updates even with a click. Regardless, you'll want to use os.startTimer and the timer event to update your clock.

no it only uptades if the desktop was open again .
Creator #4
Posted 14 April 2015 - 02:33 PM
Write some thing like this:


while true do
  local timer = os.startTimer(1)
  local event = {os.pullEvent()}
  if event[1] == "timer" then
   drawClock()
  else
	click handling code
  end
end

I hope it helped you;)

sorry forgot this:

after the else add this:

os.cancelTimer(timer)
Edited on 14 April 2015 - 12:50 PM
Leon669 #5
Posted 14 April 2015 - 02:43 PM
Write some thing like this:


while true do
  local timer = os.startTimer(1)
  local event = {os.pullEvent()}
  if event[1] == "timer" then
   drawClock()
  else
	click handling code
  end
end

I hope it helped you;)

Build it in but no clock …

Code :
while true do

local timer = os.startTimer(1)
local event = {os.pullEvent()}
local time = os.time()
local formattedTime = textutils.formatTime(time, false)
local event, button, X, Y = os.pullEvent("mouse_click")
XY = X..","..Y

if event[1] == "timer" then
term.setCursorPos(5,5)
print(formattedTime)
end
else
if XY == "48,17" and button == 1 then
shell.run"clear"
shell.run"dmenu"
end
Creator #6
Posted 14 April 2015 - 02:54 PM

while true do
local timer = os.startTimer(1)
local event = {os.pullEvent()}
if event[1] == "timer" then
local formattedTime = textutils.formatTime( os.time(), false)
term.setCursorPos(5,5)
print(formattedTime)
elseif event[1] == "mouse_click" then
if event[2] == 1 and event[3] == 48 and event[4] == 17 then
shell.run"clear"
shell.run"dmenu"
end

I cleaned up your code and made a little bit more effective.

Creator
KingofGamesYami #7
Posted 14 April 2015 - 02:55 PM
You are drawing the variable formattedTime, but never updating that value.
Creator #8
Posted 14 April 2015 - 02:57 PM
whose code are you talking about>
KingofGamesYami #9
Posted 14 April 2015 - 03:00 PM
His, you ninja'd me.
Creator #10
Posted 14 April 2015 - 03:03 PM
Muhahahahahaha, here come the evil ask a pro helper. ;)/>
Leon669 #11
Posted 14 April 2015 - 03:04 PM

while true do
local timer = os.startTimer(1)
local event = {os.pullEvent()}
if event[1] == "timer" then
local formattedTime = textutils.formatTime( os.time(), false)
term.setCursorPos(5,5)
print(formattedTime)
elseif event[1] == "mouse_click" then
if event[2] == 1 and event[3] == 48 and event[4] == 17 then
shell.run"clear"
shell.run"dmenu"
end

I cleaned up your code and made a little bit more effective.

Creator

Does not work here is the whole code (i working with a new commands now it is a bit older :D/>)


shell.run"clear"
------------------------------------------------------
Bild = paintutils.loadImage("OS/d1.img")
paintutils.drawImage(Bild,1,1)
------------------------------------------------------
term.setBackgroundColor(colors.lightGray)  
term.setTextColor(colors.white)
-----
fg = fs.open("loginSettins/version","r")
farbe = fg.readLine()
farbe = loadstring("return "..farbe)()
fg.close()
------------------------------------------------------
paintutils.drawPixel(49,17, colors.blue)
paintutils.drawPixel(50,18, colors.blue)
paintutils.drawPixel(50,17, colors.blue)
paintutils.drawPixel(49,18, colors.blue)
paintutils.drawPixel(48,17, colors.blue)
paintutils.drawPixel(48,18, colors.blue)






term.setTextColor(colors.gray)
term.setBackgroundColor(colors.white)
term.setCursorPos(1,7)
print("Settings")
term.setCursorPos(2,12)
print(" News")
term.setCursorPos(2,17)
print(" Worm")
term.setCursorPos(11,7)
print("ChromeMenu")
term.setCursorPos(13,12)
print("NPaint")
term.setCursorPos(13,17)
print("XFiles")
term.setTextColor(colors.white)
term.setBackgroundColor(colors.blue)
term.setCursorPos(48,17)
print("")
term.setCursorPos(48,18)



paintutils.drawPixel(3,4,40000)
paintutils.drawPixel(4,4,40000)
paintutils.drawPixel(5,4,40000)
paintutils.drawPixel(6,4,40000)
paintutils.drawPixel(3,5,40000)
paintutils.drawPixel(6,5,40000)
paintutils.drawPixel(3,6,40000)
paintutils.drawPixel(4,6,40000)
paintutils.drawPixel(5,6,40000)
paintutils.drawPixel(6,6,40000)
------------
paintutils.drawPixel(3,9,3000)
paintutils.drawPixel(4,9,3000)
paintutils.drawPixel(5,9,3000)
paintutils.drawPixel(6,9,3000)
paintutils.drawPixel(3,10,3000)
paintutils.drawPixel(6,10,3000)
paintutils.drawPixel(3,11,3000)
paintutils.drawPixel(4,11,3000)
paintutils.drawPixel(5,11,3000)
paintutils.drawPixel(6,11,3000)
---------------
paintutils.drawPixel(3,14,20000)
paintutils.drawPixel(4,14,20000)
paintutils.drawPixel(5,14,20000)
paintutils.drawPixel(6,14,20000)
paintutils.drawPixel(3,15,20000)
paintutils.drawPixel(6,15,20000)
paintutils.drawPixel(3,16,20000)
paintutils.drawPixel(4,16,20000)
paintutils.drawPixel(5,16,20000)
paintutils.drawPixel(6,16,20000)
--------------
paintutils.drawPixel(14,4,33)
paintutils.drawPixel(15,4,33)
paintutils.drawPixel(16,4,33)
paintutils.drawPixel(17,4,33)
paintutils.drawPixel(14,5,33)
paintutils.drawPixel(17,5,33)
paintutils.drawPixel(14,6,33)
paintutils.drawPixel(15,6,33)
paintutils.drawPixel(16,6,33)
paintutils.drawPixel(17,6,33)
-------------------
paintutils.drawPixel(14,9,17)
paintutils.drawPixel(15,9,17)
paintutils.drawPixel(16,9,17)
paintutils.drawPixel(17,9,17)
paintutils.drawPixel(14,10,17)
paintutils.drawPixel(17,10,17)
paintutils.drawPixel(14,11,17)
paintutils.drawPixel(15,11,17)
paintutils.drawPixel(16,11,17)
paintutils.drawPixel(17,11,17)
----------------------
paintutils.drawPixel(14,14,9)
paintutils.drawPixel(15,14,9)
paintutils.drawPixel(16,14,9)
paintutils.drawPixel(17,14,9)
paintutils.drawPixel(14,15,9)
paintutils.drawPixel(17,15,9)
paintutils.drawPixel(14,16,9)
paintutils.drawPixel(15,16,9)
paintutils.drawPixel(16,16,9)
paintutils.drawPixel(17,16,9)
---------------

paintutils.drawLine(1, 1, 51, 1, tonumber(farbe))





------------


term.setTextColor(colors.black)
shell.run"cd //"
file = fs.open("loginSettins/curUser", "r")
version = file.readLine()
file.close()
term.setCursorPos(1,1)
print(version)
shell.run"cd //"
shell.run"cd OS"


local event, button, X, Y = os.pullEvent("mouse_click")
XY = X..","..Y

-------------------FORMEL----------------------------------------
while true do
local timer = os.startTimer(1)
local event = {os.pullEvent()}
if event[1] == "timer" then
local formattedTime = textutils.formatTime( os.time(), false)
term.setCursorPos(5,5)
print(formattedTime)
else
  if XY == "48,17" and button == 1 then
  shell.run"clear"
  shell.run"dmenu"
  end

  if XY == "49,17" and button == 1 then
  shell.run"clear"
  shell.run"dmenu"
  end

   if XY == "50,17" and button == 1 then
  shell.run"clear"
  shell.run"dmenu"
  end

   if XY == "48,18" and button == 1 then
  shell.run"clear"
  shell.run"dmenu"
  end

	if XY == "49,18" and button == 1 then
  shell.run"clear"
  shell.run"dmenu"
  end

	if XY == "50,18" and button == 1 then
  shell.run"clear"
  shell.run"dmenu"
  end

------------------------ICON1 Z1--------------------------------------
  if XY == "3,6" and button == 1 then
  shell.run"clear"
  shell.run"settings"
  end

  if XY == "4,6" and button == 1 then
  shell.run"clear"
  shell.run"settings"
  end

  if XY == "5,6" and button == 1 then
  shell.run"clear"
  shell.run"settings"
  end

  if XY == "6,6" and button == 1 then
  shell.run"clear"
  shell.run"settings"
  end
--------------------------------Icon1 Z2-------------------------------
  if XY == "3,5" and button == 1 then
  shell.run"clear"
  shell.run"settings"
  end

  if XY == "4,5" and button == 1 then
  shell.run"clear"
  shell.run"settings"
  end

  if XY == "5,5" and button == 1 then
  shell.run"clear"
  shell.run"settings"
  end

  if XY == "6,5" and button == 1 then
  shell.run"clear"
  shell.run"settings"
  end
  ----------------------------Icon1 Z3---------------------------------
  if XY == "3,4" and button == 1 then
  shell.run"clear"
  shell.run"settings"
  end

  if XY == "4,4" and button == 1 then
  shell.run"clear"
  shell.run"settings"
  end

  if XY == "5,4" and button == 1 then
  shell.run"clear"
  shell.run"settings"
  end

  if XY == "6,4" and button == 1 then
  shell.run"clear"
  shell.run"settings"
  end

-------------------------------------------------------------------------
------------------------Icon 2 z1-----------------------------------------
-----------------------------------------------------------------------------
  if XY == "3,11" and button == 1 then
  shell.run"e"
  break
  end

  if XY == "4,11" and button == 1 then
  shell.run"e"
  break
  end

  if XY == "5,11" and button == 1 then
  shell.run"e"
  break
  end

  if XY == "6,11" and button == 1 then
  shell.run"e"
  break
  end
----------------------------------------Icon2 z2----------------------------+
  if XY == "3,10" and button == 1 then
  shell.run"e"
  break
  end  

  if XY == "4,10" and button == 1 then
  shell.run"e"
  break
  end

  if XY == "5,10" and button == 1 then
  shell.run"e"
  break
  end

  if XY == "6,10" and button == 1 then
  shell.run"e"
  break
  end
--------------------------------------Icon2 z3--------------------------------------
  if XY == "3,9" and button == 1 then
  shell.run"e"
  break
  end  

  if XY == "4,9" and button == 1 then
  shell.run"e"
  break
  end

  if XY == "5,9" and button == 1 then
  shell.run"e"
  break
  end

  if XY == "6,9" and button == 1 then
  shell.run"e"
  break
  end
------------------------------------------------------------------------------------
-------------------------------------Icon3 Z1---------------------------------------
------------------------------------------------------------------------------------
  if XY == "3,16" and button == 1 then
  shell.run"clear"
  term.setBackgroundColor(colors.black)
  sleep(1)
  shell.run"worm"
  shell.run"desktop"
  break
  end

  if XY == "4,16" and button == 1 then
	shell.run"clear"
  term.setBackgroundColor(colors.black)
  sleep(1)
  shell.run"worm"
  shell.run"desktop"
  break
  end

  if XY == "5,16" and button == 1 then
	shell.run"clear"
  term.setBackgroundColor(colors.black)
  sleep(1)
  shell.run"worm"
  shell.run"desktop"
  break
  end

  if XY == "6,16" and button == 1 then
	shell.run"clear"
  term.setBackgroundColor(colors.black)
  sleep(1)
  shell.run"worm"
  shell.run"desktop"
  break
  end
  -----------------------------------Icon3 Z2----------------------------------------
  if XY == "3,15" and button == 1 then
	shell.run"clear"
  term.setBackgroundColor(colors.black)
  sleep(1)
  shell.run"worm"
  shell.run"desktop"
  break
  end

  if XY == "4,15" and button == 1 then

	shell.run"clear"
  term.setBackgroundColor(colors.black)
  sleep(1)
  shell.run"worm"
  shell.run"desktop"
  break
  end

  if XY == "5,15" and button == 1 then
  shell.run"clear"
  term.setBackgroundColor(colors.black)
  sleep(1)
  shell.run"worm"
  shell.run"desktop"
  break
  end

  if XY == "6,15" and button == 1 then
	shell.run"clear"
  term.setBackgroundColor(colors.black)
  sleep(1)
  shell.run"worm"
  shell.run"desktop"
  break
  end
  -------------------------------------Icon3 Z3--------------------------------------
  if XY == "3,14" and button == 1 then
	shell.run"clear"
  term.setBackgroundColor(colors.black)
  sleep(1)
  shell.run"worm"
  shell.run"desktop"
  break
  end

  if XY == "4,14" and button == 1 then
	shell.run"clear"
  term.setBackgroundColor(colors.black)
  sleep(1)
  shell.run"worm"
  shell.run"desktop"
  break
  end

  if XY == "5,14" and button == 1 then
	shell.run"clear"
  term.setBackgroundColor(colors.black)
  sleep(1)
  shell.run"worm"
  shell.run"desktop"
  break
  end

  if XY == "6,14" and button == 1 then
	shell.run"clear"
  term.setBackgroundColor(colors.black)
  sleep(1)
  shell.run"worm"
  shell.run"desktop"
  break
  end  
--------------------------------------------------------------------


-------------------------------------------------------------------
  if XY == "14,6" and button == 1 then
  shell.run"clear"
  shell.run"chromestore"
  break
  end

if XY == "15,6" and button == 1 then
  shell.run"clear"
  shell.run"chromestore"
  break
  end

if XY == "16,6" and button == 1 then
  shell.run"clear"
  shell.run"chromestore"
  break
  end

if XY == "17,6" and button == 1 then
  shell.run"clear"
  shell.run"chromestore"
  break
  end
-----
  if XY == "14,5" and button == 1 then
  shell.run"clear"
  shell.run"chromestore"
  break
  end

if XY == "15,5" and button == 1 then
  shell.run"clear"
  shell.run"chromestore"
  break
  end

if XY == "16,5" and button == 1 then
  shell.run"clear"
  shell.run"chromestore"
  break
  end

if XY == "17,5" and button == 1 then
  shell.run"clear"
  shell.run"chromestore"
  break
  end
----
   if XY == "14,4" and button == 1 then
  shell.run"clear"
  shell.run"chromestore"
  break
  end

if XY == "15,4" and button == 1 then
  shell.run"clear"
  shell.run"chromestore"
  break
  end

if XY == "16,4" and button == 1 then
  shell.run"clear"
  shell.run"chromestore"
  break
  end

if XY == "17,4" and button == 1 then
  shell.run"clear"
  shell.run"chromestore"
  break
  end
-------------------------------------------
   if XY == "14,9" and button == 1 then
   shell.run"clear"
  shell.run"npaint"
  shell.run"desktop"
  end

   if XY == "15,9" and button == 1 then
   shell.run"clear"
  shell.run"npaint"
  shell.run"desktop"
  end	

  if XY == "16,9" and button == 1 then
  shell.run"clear"
  shell.run"npaint"
  shell.run"desktop"
  end

   if XY == "17,9" and button == 1 then
   shell.run"clear"
  shell.run"npaint"
  shell.run"desktop"
  end

   if XY == "14,10" and button == 1 then
   shell.run"clear"
  shell.run"npaint"
  shell.run"desktop"
  end	

   if XY == "15,10" and button == 1 then
   shell.run"clear"
  shell.run"npaint"
  shell.run"desktop"
  end

   if XY == "16,10" and button == 1 then
   shell.run"clear"
  shell.run"npaint"
  shell.run"desktop"
  end

   if XY == "17,10" and button == 1 then
   shell.run"clear"
  shell.run"npaint"
  shell.run"desktop"
  end

   if XY == "14,11" and button == 1 then
   shell.run"clear"
  shell.run"npaint"
  shell.run"desktop"
  end

   if XY == "15,11" and button == 1 then
   shell.run"clear"
  shell.run"npaint"
  shell.run"desktop"
  end

   if XY == "16,11" and button == 1 then
   shell.run"clear"
  shell.run"npaint"
  shell.run"desktop"
  end

   if XY == "17,11" and button == 1 then
   shell.run"clear"
  shell.run"npaint"
  shell.run"desktop"
  end  
----------------------------------------
   if XY == "14,15" and button == 1 then
   shell.run"clear"
  shell.run"filebrowser"
  shell.run"desktop"
  end

	 if XY == "15,15" and button == 1 then
   shell.run"clear"
  shell.run"filebrowser"
  shell.run"desktop"
  end

	 if XY == "16,15" and button == 1 then
   shell.run"clear"
  shell.run"filebrowser"
  shell.run"desktop"
  end

	 if XY == "17,15" and button == 1 then
   shell.run"clear"
  shell.run"filebrowser"
  shell.run"desktop"
  end

	 if XY == "14,16" and button == 1 then
   shell.run"clear"
  shell.run"filebrowser"
  shell.run"desktop"
  end

	 if XY == "15,16" and button == 1 then
   shell.run"clear"
  shell.run"filebrowser"
  shell.run"desktop"
  end

	 if XY == "16,16" and button == 1 then
   shell.run"clear"
  shell.run"filebrowser"
  shell.run"desktop"
  end

	 if XY == "17,16" and button == 1 then
   shell.run"clear"
  shell.run"filebrowser"
  shell.run"desktop"
  end

	 if XY == "14,14" and button == 1 then
   shell.run"clear"
  shell.run"filebrowser"
  shell.run"desktop"
  end

	 if XY == "15,14" and button == 1 then
   shell.run"clear"
  shell.run"filebrowser"
  shell.run"desktop"
  end

	 if XY == "16,14" and button == 1 then
   shell.run"clear"
  shell.run"filebrowser"
  shell.run"desktop"
  end

	 if XY == "17,14" and button == 1 then
   shell.run"clear"
  shell.run"filebrowser"
  shell.run"desktop"
  end
end  
end


I have to clean this code :D/> :D/>
Edited on 14 April 2015 - 01:05 PM
Creator #12
Posted 14 April 2015 - 03:09 PM
Your code is a little bit of a mess. I see you are using loads of bottons. If you want to relieve your work, try Interact. I'll explain to you how it works. ;)/>
Leon669 #13
Posted 14 April 2015 - 03:15 PM
Your code is a little bit of a mess. I see you are using loads of bottons. If you want to relieve your work, try Interact. I'll explain to you how it works. ;)/>

I have to clean this code :D/> :D/>

But sure how does it work
Creator #14
Posted 14 April 2015 - 03:17 PM
Here is a link to the wiki. Expect the documentation to be ready in some 30 mins.
Anavrins #15
Posted 14 April 2015 - 03:17 PM

while true do
  local timer = os.startTimer(1)
  local event = {os.pullEvent()}
  if event[1] == "timer" then
   drawClock()
  else
	click handling code
  end
end

This results into some weird timing, each time you click, a new clock starts ticking.
So you don't get a timer event each seconds anymore, I would recommend something like this instead if you really want it each seconds.

local timer = os.startTimer(1)
while true do
  local event = {os.pullEvent()}
  if event[1] == "timer" and event[2] == timer then
    drawClock()
    timer = os.startTimer(1)
  else
    click handling code
  end
end
Edited on 14 April 2015 - 01:18 PM
Leon669 #16
Posted 14 April 2015 - 03:21 PM

while true do
  local timer = os.startTimer(1)
  local event = {os.pullEvent()}
  if event[1] == "timer" then
   drawClock()
  else
	click handling code
  end
end

This results into some weird timing, each time you click, a new clock starts ticking.
So you don't get a timer event each seconds anymore, I would recommend something like this instead if you really want it each seconds.

local timer = os.startTimer(1)
while true do
  local event = {os.pullEvent()}
  if event[1] == "timer" and event[2] == timer then
	drawClock()
	timer = os.startTimer(1)
  else
	click handling code
  end
end

desktop:143 attempt to call nil
KingofGamesYami #17
Posted 14 April 2015 - 03:23 PM
You'll need to define the drawClock() function for either of those code snippets to work.
Leon669 #18
Posted 14 April 2015 - 03:29 PM
Here is a link to the wiki. Expect the documentation to be ready in some 30 mins.

I dont know why but the website doesnt open i see only the github logo and nothing more

You'll need to define the drawClock() function for either of those code snippets to work.

could you do that in my code ? :D/>
KingofGamesYami #19
Posted 14 April 2015 - 03:34 PM
Well no, basically just put the clock drawing code inside it. It's up to you how it works.
Creator #20
Posted 14 April 2015 - 03:42 PM
Now, you can use the link ;)/>