This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
snoble2022's profile picture

[Lua] [networking] Github downloader error

Started by snoble2022, 10 December 2012 - 08:32 AM
snoble2022 #1
Posted 10 December 2012 - 09:32 AM
Hello, I'm going to get to the point.

To start off this is an api and i didn't upload the whole thing here. Stuff like 'setColor(color)' and 'titleBar(title)' does work.
Note: this error is not an exact repeat
ERROR: Line 41: Attempt to index (a nil value ?)

EDIT: I also figured out it doesn't always error sometimes it passes http_failure when i know the site exists

Spoiler



os.loadAPI("RoxorBrowser/filec")

function exitToHome()
os.run({}, "RoxorBrowser/browser")
end

function setColor(color)
local line = 1
for i=1,19 do
term.setCursorPos(1,line)
term.setBackgroundColor(color)
print("												")
local line = line + 1
end
end

function titleBar( sUrl )
term.setCursorPos(1,1)
term.clearLine()
term.setCursorPos(1,1)
term.setBackgroundColor(colors.lightGray)
term.setTextColor(colors.gray)
print("												")
term.setCursorPos(1,1)
print("URL: http://"..sUrl)
end

function showError( sErrorText )
term.clear()
term.setCursorPos(1,1)
setColor(colors.blue)
titleBar("Error")
term.setBackgroundColor(colors.blue)
term.setTextColor(colors.white)
print(sErrorText)
print("System: Press any key to continue...")
os.pullEvent("key")
os.run({}, "RoxorBrowser/browser")
end

function loadWebpage( sUrl )
local Url = "https://raw.github.com/ComputercraftHostingExtreme/roxor_host_service/roxor_webpages/roxor_webpages/"..sUrl
local webpage = http.request(Url)
sEvent, p1, p2, p3, p4, p5 = os.pullEvent()
if sEvent == "http_success" then
webpageD = webpage.readAll()
webpage.close()
filec.fWrite("RoxorBrowser/TempFiles/webpage.ts", webpageD)

if filec.readLine("RoxorBrowser/TempFiles/webpage.ts", 1) == "--RoxorBrowser v1.0.0" then
os.run({}, "RoxorBrowser/TempFiles/webpage.ts")
os.run({}, "RoxorBrowser/browser")
else
term.clear()
setColor(colors.blue)
titleBar("error")
term.setCursorPos(1,2)
term.setBackgroundColor(colors.blue)
term.setTextColor(colors.white)
showError("System: Not designed for the newest Roxor")
end
elseif sEvent == "http_failure" then
showError("System: Website doen't exist or your connection is bad")
else
loadWebpage( sUrl )
end
end
Lyqyd #2
Posted 10 December 2012 - 09:40 AM
I don't see a declaration for filec. Please post the whole code.
snoble2022 #3
Posted 10 December 2012 - 09:42 AM
Ok Lyqyd, however this is an api.
Lyqyd #4
Posted 10 December 2012 - 11:27 AM
Yep, still don't see a declaration for filec. Where is filec supposed to come from?