Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- precision = 10
- defaultLength = 12000
- lines = 4
- args = { ... }
- timerLength = false
- function main()
- if #args > 0 then
- timerLength = tonumber(args[1])
- setFS("time",timerLength)
- setFS("cycle","0")
- setFS("pos","0")
- else
- timerLength = tonumber(getFS("time"))
- if not timerLength then
- timerLength = defaultLength
- end
- end
- resuming = getFS("cycle")
- cycle = 1
- term.clear()
- writeCentered("[RED TIMER]",0,lines)
- while (true) do
- if resuming then
- cycle = resuming
- resuming = false
- timerPos = tonumber(getFS("pos"))
- else
- timerPos = timerLength
- end
- setFS("cycle",cycle)
- while timerPos > 0 do
- percent = 100 - math.ceil( timerPos*100 / timerLength )
- writeCentered("cycle: "..cycle,1,lines)
- writeCentered(timerPos.."/"..timerLength.." "..percent.."%",2,lines)
- writeCentered(getpString(percent),3,lines)
- os.sleep(precision)
- timerPos = timerPos - precision
- setFS("pos",timerPos)
- end
- rs.setOutput("back", true)
- writeCentered("[EMIT SIGNAL]",3,lines)
- sleep(2)
- rs.setOutput("back", false)
- cycle = cycle + 1
- end
- end
- function setFS(name,value)
- file = io.open("timer."..name,"w")
- file:write(value)
- file:close()
- end
- function getFS(name)
- local result = false
- file = io.open("timer."..name, "r")
- if file==nil then
- return 0
- end
- result = file:read()
- file:close()
- return result
- end
- function getpString(percent)
- local x, y = term.getSize()
- local string = "["
- for i = 0,x-8 do
- if (i < (percent/100 * (x - 8))) then
- string = string.."#"
- else
- string = string.."-"
- end
- end
- return string.."]"
- end
- function writeCentered( text , yd , yLines)
- local x, y = term.getSize()
- local centerYPos = ((y - yLines) / 2)
- local centerXStartingPos = ( x - string.len(text) ) / 2
- term.setCursorPos( centerXStartingPos, centerYPos + yd )
- term.clearLine()
- write( text )
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment