Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Setup
- local monitor = peripheral.wrap("top")
- local tripwire_ignored = true
- local tripwire_positions = {}
- local position_counter = 0
- -- Function to display countdown
- function countdown()
- monitor.write("Starting countdown")
- for i = 10, 1, -1 do
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.write("Countdown: " .. i)
- sleep(1)
- end
- end
- -- Function to update timer
- function updateTimer(startTime)
- monitor.write("Entered updateTimer")
- while true do
- local currentTime = os.epoch("utc")
- local elapsedTime = (currentTime - startTime) / 1000
- monitor.setCursorPos(1, 2)
- monitor.write("Elapsed time: " .. elapsedTime .. "s ")
- if elapsedTime > 10 then
- tripwire_ignored = false
- monitor.write("Tripwire is now active")
- end
- sleep(1)
- end
- end
- -- Function to listen for tripwire
- function listenForTripwire()
- while true do
- local event, side = os.pullEvent("redstone")
- if side == "right" and redstone.getInput("right") then
- if not tripwire_ignored then
- local currentTime = os.epoch("utc")
- position_counter = position_counter + 1
- table.insert(tripwire_positions, {position = position_counter, time = currentTime})
- monitor.setCursorPos(1, 5 + position_counter) -- Changed line
- monitor.write("Position " .. position_counter .. ": " .. (currentTime / 1000) .. "s ") -- Extra spaces to clear previous text
- end
- end
- end
- end
- -- Main event loop
- while true do
- local event, side, xPos, yPos = os.pullEvent("monitor_touch")
- if side == "top" then
- tripwire_ignored = true
- position_counter = 0
- tripwire_positions = {}
- countdown()
- local startTime = os.epoch("utc")
- parallel.waitForAny(function() updateTimer(startTime) end, listenForTripwire)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement