Posted 21 May 2013 - 06:41 PM
I have a program that uses a parallel to download a file while a loading bar is being shown. The thing is, the loading bar is taking priority over the download and the file won't download until the loading bar stops. The thing is, the download function tells the loading bar when to stop, so until the download finishes, the loading bar will keep going until the download starts, which won't because of the loading bar. Please help! Here is the code (I have the download function set to wait 5 seconds because I will have more then one file.) The loading bar ISN'T one of those annoying loading bars that are fake. It waits for the download to finish. Just an FYI. Also, this code is ALL me. No help at all.
--Setting the colors
term.setBackgroundColor(colors.white)
term.setTextColor(colors.cyan)
term.clear()
term.setCursorPos(1,1)
loading = "yes"
local installing = true
--Functions
local function centerPrint(text)
local x, y = term.getSize()
local x2, y2 = term.getCursorPos()
term.setCursorPos(math.ceil((x/2) -(text:len()/2)), y2)
write(text)
term.setCursorPos(1,1)
end
local function load(yLoc)
w, h = term.getSize()
local x2, y2 = term.getCursorPos()
loc = math.ceil(w/2)
loc2 = yLoc
while loading == "yes" do
term.setCursorPos(loc-2, loc2)
print("----")
sleep(0.5)
term.setCursorPos(loc-2, loc2)
print("O---")
term.setCursorPos(loc-2, loc2)
sleep(0.5)
print("-O--")
term.setCursorPos(loc-2, loc2)
sleep(0.5)
print("--O-")
term.setCursorPos(loc-2, loc2)
sleep(0.5)
print("---O")
term.setCursorPos(loc-2, loc2)
sleep(0.5)
print("--O-")
term.setCursorPos(loc-2, loc2)
sleep(0.5)
print("-O--")
term.setCursorPos(loc-2, loc2)
sleep(0.5)
print("O---")
term.setCursorPos(loc-2, loc2)
sleep(0.5)
end
end
function downloadFiles()
w, h = term.getSize()
term.setCursorPos(1, h-1)
shell.run("pastebin", "get", "1EzJKSLn", "rn")
sleep(5)
installing = false
loading = "no"
end
--Main Code
centerPrint("RedOS Installer")
term.setCursorPos(1, 4)
centerPrint("Installing Files....")
parallel.waitForAny(downloadFiles, load(9))
term.clear()
print("Installed!")