superanonymous

In-game real-world clock

Feb 20th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.02 KB | None | 0 0
  1. --3-letter time zone code
  2. timezone="est"
  3. --Do you want 24-hour time?
  4. militarytime=false
  5. --Colors
  6. ctime="white"
  7. campm="white"
  8. cbg="black"
  9.  
  10. --Don't touch the rest or it may break
  11.  
  12. --Formatting Variables
  13. ampm=""
  14.  
  15. m = peripheral.wrap("right")
  16.  
  17. m.setTextScale(4)
  18.  
  19. function extract()
  20.  
  21. timelong=nil
  22. timelong=timelonge.readAll()
  23.  
  24. end
  25.  
  26. while true do
  27. timelonge=http.get("http://www.timeapi.org/"..timezone)
  28. repeat
  29. pcall(extract)
  30. until timelong~=nil
  31. hour=tonumber(string.sub(timelong,12,13,"%0"))
  32. minute=tonumber(string.sub(timelong,15,16,"%0"))
  33.  
  34. if militarytime==false then
  35.  
  36. if hour>12 then
  37.  
  38. hour=hour-12
  39. ampm="PM"
  40.  
  41. else
  42.  
  43. ampm="AM"
  44.  
  45. end
  46.  
  47. if hour==0 then
  48.  
  49. hour=12
  50.  
  51. end
  52.  
  53. end
  54.  
  55. if hour<10 then
  56.  
  57. hours=" "..tostring(hour)
  58.  
  59. else
  60.  
  61. hours=tostring(hour)
  62.  
  63. end
  64.  
  65. minutes=tostring(minute)
  66.  
  67. if minute<10 then
  68. minutes="0"..tostring(minute)
  69. end
  70.  
  71. time=hours..":"..minutes.." "..ampm
  72.  
  73. timeold=time
  74.  
  75. if time~=oldtime then
  76.  
  77. m.clear()
  78. m.setCursorPos(1,1)
  79. m.write(" "..time)
  80.  
  81. end
  82.  
  83. sleep(5)
  84.  
  85. end
Advertisement
Add Comment
Please, Sign In to add comment