Advertisement
MrHG

timer

Nov 29th, 2022 (edited)
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. function displayTime(time)
  2. minutes = 0
  3. while time >= 60 do
  4. time = time-60
  5. minutes = minutes + 1
  6. end
  7. seconds = time
  8. if minutes < 10 then
  9. minutes = "0"..tostring(minutes)
  10. else
  11. minutes = tostring(minutes)
  12. end
  13. if seconds < 10 then
  14. seconds = "0"..tostring(seconds)
  15. else
  16. seconds = tostring(seconds)
  17. end
  18. return minutes..":"..seconds
  19. end
  20.  
  21. timer = 1200
  22. monitor_1 = peripheral.wrap("back")
  23. monitor_2 = peripheral.wrap("monitor_0")
  24. monitor_1.setTextScale(5)
  25. monitor_2.setTextScale(5)
  26. xSize, ySize = monitor_1.getSize()
  27. while true do
  28. if timer < 0 then
  29. monitor_1.setBackgroundColor(colors.white)
  30. monitor_2.setBackgroundColor(colors.white)
  31. monitor_1.setTextColor(colors.black)
  32. monitor_2.setTextColor(colors.black)
  33. text = "Time!"
  34. else
  35. text = displayTime(timer)
  36. end
  37. monitor_1.clear()
  38. monitor_2.clear()
  39. monitor_1.setCursorPos(xSize/2-(string.len(text)/2)+1,ySize/2+1)
  40. monitor_2.setCursorPos(xSize/2-(string.len(text)/2)+1,ySize/2+1)
  41. monitor_1.write(text)
  42. monitor_2.write(text)
  43. timer = timer - 1
  44. sleep(1)
  45. if timer < -1 then
  46. os.pullEvent("key")
  47. monitor_1.setBackgroundColor(colors.black)
  48. monitor_2.setBackgroundColor(colors.black)
  49. monitor_1.setTextColor(colors.white)
  50. monitor_2.setTextColor(colors.white)
  51. monitor_1.clear()
  52. monitor_2.clear()
  53. break
  54. end
  55. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement