Posted 23 February 2012 - 03:07 AM
[left]
This is a repository with all of the functions me (xgaarocha) and my friend (bravejuliano) created and are useful outside of our in-development Operational System. Bear in mind we have a "If it works it's good for now" policy currently, which means we will make it work first, finish the OS then optimize things. We don't guarantee 100% security and stability of our functions.
> Functions List_[/left]
[left]Delay[/left]
[left]Function: Creates an interval with seconds/minutes/hours and can show a countdown.[/left]
[left]Usage: interval(s, m, h, tleft) (Eg.: interval (0, 2, 0, "yes") > Shows a countdown of 2 minutes)[/left]
[left]Parameters: s,m,h = seconds, minutes, hours / rleft = "yes" enables coutdown, leave blank or "no" to disable it.[/left]
[left]Loading/Progress Bar
Function: Creates a bar that fills-up in a determined amount of time.[/left]
Usage: loadbar(s, char, size) (Eg.: loadbar(10, #, 10, "yes") > Creates a bar that fills up in 10 seconds with 10 #)
Parameters: s = duration in seconds / char = the character the bar is made of / size = bar's size, leave blank for auto
This is a repository with all of the functions me (xgaarocha) and my friend (bravejuliano) created and are useful outside of our in-development Operational System. Bear in mind we have a "If it works it's good for now" policy currently, which means we will make it work first, finish the OS then optimize things. We don't guarantee 100% security and stability of our functions.
> Functions List_[/left]
- Delay
- Loading/Progress Bar
[left]Delay[/left]
[left]Function: Creates an interval with seconds/minutes/hours and can show a countdown.[/left]
[left]Usage: interval(s, m, h, tleft) (Eg.: interval (0, 2, 0, "yes") > Shows a countdown of 2 minutes)[/left]
[left]Parameters: s,m,h = seconds, minutes, hours / rleft = "yes" enables coutdown, leave blank or "no" to disable it.[/left]
Spoiler
function delay(s, m, h, tleft)
-- Define parameters and vars
s = s or 1
m = m or 0
h = h or 0
tleft = tleft or "no"
delay = s + m*60 + h*3600
-- Check for negative numbers
if s < 0 then error("Delay time can only be positive") end
if m < 0 then error("Delay time can only be positive") end
if h < 0 then error("Delay time can only be positive") end
if s+m+h == 0 then error("Delay time can only be positive") end
-- Delay without time left
if tleft == "no" then
sleep(delay)
end
-- Delay with time left
if tleft == "yes" then
while delay ~= 0 do
h = math.floor(delay/3600)
m = math.floor(delay/60 - h*60)
s = math.floor(delay -h*3600 -m*60)
print("[", h, ":", m, ":", s, "]")
sleep(1)
delay = delay - 1
term.clear()
term.setCursorPos( 1, 1 )
end
end
end
[left]Loading/Progress Bar
Function: Creates a bar that fills-up in a determined amount of time.[/left]
Usage: loadbar(s, char, size) (Eg.: loadbar(10, #, 10, "yes") > Creates a bar that fills up in 10 seconds with 10 #)
Parameters: s = duration in seconds / char = the character the bar is made of / size = bar's size, leave blank for auto
Spoiler
function loadbar(s, char, size)
-- Define parameters
s = s or 5
size = size or swidth
char = char or "#"
local xpos,ypos = term.getCursorPos()
local delay = s/size
local start = 1
while start < size do
term.setCursorPos(start, ypos)
print (char)
sleep(delay)
start = start + 1
end
end