Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- By: Stefan B
- -- Website: beapython.dev
- -- Contact : beapythondev@gmail.com
- --
- -- youtube.com/beapythondev
- -- Youtube Video in progress
- -- Initialize our variables
- cur_split = -1
- num_splits = 4
- mon_y = 1
- mon = peripheral.wrap("right")
- total_time = 0
- time_start = nil
- prev_split_start = nil
- -- Functions
- function inc_mon ()
- mon_y = mon_y + 1
- mon.setCursorPos(1,mon_y)
- return
- end
- -- Initialize our monitor
- mon.clear()
- mon.setCursorPos(1,mon_y)
- mon.write("Parkour Challenge")
- inc_mon()
- mon.write("Waiting for runner")
- while true do
- os.pullEvent("redstone") -- wait for a "redstone" event
- split_event = 15 - rs.getAnalogueInput("left")
- if rs.getInput("left") then -- check the input
- if cur_split == split_event - 1 then
- if split_event == 0 then
- time_start = os.clock()
- prev_split_start = time_start
- mon.clear()
- mon_y = 1
- total_time = 0
- mon.setCursorPos(1,mon_y)
- mon.write("Parkour Challenge")
- inc_mon()
- mon.write("Good luck runner")
- elseif split_event > 0 then
- cur_time = os.clock()
- split_time = cur_time - prev_split_start
- prev_split_start = cur_time
- total_time = total_time + split_time
- inc_mon()
- mon.write(split_event)
- mon.write(" : ")
- mon.write(string.format("%." .. (2 or 0) .. "f", split_time))
- end
- if split_event == num_splits then
- cur_split = -1
- inc_mon()
- inc_mon()
- mon.write("Total time")
- inc_mon()
- mon.write(string.format("%." .. (2 or 0) .. "f", total_time))
- mon.setCursorPos(1,2)
- mon.clearLine()
- mon.write("Waiting for runner")
- else
- cur_split = split_event
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement