Advertisement
Mojokojo69

Untitled

Sep 1st, 2023 (edited)
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. -- Setup
  2. local monitor = peripheral.wrap("top")
  3. local tripwire_ignored = true
  4. local tripwire_positions = {}
  5. local position_counter = 0
  6.  
  7. -- Function to display countdown
  8. function countdown()
  9. monitor.write("Starting countdown")
  10. for i = 10, 1, -1 do
  11. monitor.clear()
  12. monitor.setCursorPos(1, 1)
  13. monitor.write("Countdown: " .. i)
  14. sleep(1)
  15. end
  16. end
  17.  
  18. -- Function to update timer
  19. function updateTimer(startTime)
  20. monitor.write("Entered updateTimer")
  21. while true do
  22. local currentTime = os.epoch("utc")
  23. local elapsedTime = (currentTime - startTime) / 1000
  24. monitor.setCursorPos(1, 2)
  25. monitor.write("Elapsed time: " .. elapsedTime .. "s ")
  26.  
  27. if elapsedTime > 10 then
  28. tripwire_ignored = false
  29. monitor.write("Tripwire is now active")
  30. end
  31. sleep(1)
  32. end
  33. end
  34.  
  35. -- Function to listen for tripwire
  36. function listenForTripwire()
  37. while true do
  38. local event, side = os.pullEvent("redstone")
  39. if side == "right" and redstone.getInput("right") then
  40. if not tripwire_ignored then
  41. local currentTime = os.epoch("utc")
  42. position_counter = position_counter + 1
  43. table.insert(tripwire_positions, {position = position_counter, time = currentTime})
  44. monitor.setCursorPos(1, 5 + position_counter) -- Changed line
  45. monitor.write("Position " .. position_counter .. ": " .. (currentTime / 1000) .. "s ") -- Extra spaces to clear previous text
  46. end
  47. end
  48. end
  49. end
  50.  
  51. -- Main event loop
  52. while true do
  53. local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  54.  
  55. if side == "top" then
  56. tripwire_ignored = true
  57. position_counter = 0
  58. tripwire_positions = {}
  59. countdown()
  60. local startTime = os.epoch("utc")
  61. parallel.waitForAny(function() updateTimer(startTime) end, listenForTripwire)
  62. end
  63. end
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement