local function checkVersion()
print("Getting latest version...")
local response = http.get(rawRepoLocation.."version") --Gets version on GitHub
if reponse then
githubVersion = tonumber(response.readAll())
end
if (githubVersion ~= nil) then
if (fs.exists("NB-Storage/version") == true) then --Gets current version
local file = fs.open("NB-Storage/version", "r")
localVersion = tonumber(file.readAll())
file.close()
else
return "not installed"
end
if (githubVersion > localVersion) then --Checks if GitHub version is newer
return true
else
return false
end
else --If can't get to GitHub
return
end
end
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Can't figure out why this is returning nil
Started by Selim, 23 April 2015 - 09:54 PMPosted 23 April 2015 - 11:54 PM
So, I am working on an installer/updater for a project I am working on, and I can't figure out why my function is returning nil. It should only be able to return nil if it can't get to GitHub, but I tested the same functions in the Lua console, but I can't figure it out.
Edited on 23 April 2015 - 10:00 PM
Posted 23 April 2015 - 11:57 PM
Is it returning nil, or false?
What's "rawRepoLocation"?
What's "rawRepoLocation"?
Posted 23 April 2015 - 11:58 PM
It returns nil, and rawRepoLocation is the raw location of the repository on GitHub. I know it can get the file fine if that is what you are getting at.
Posted 24 April 2015 - 12:01 AM
If by "file" you mean whatever rawRepoLocation.."version" resolves to, then that suggests that response.readAll() simply cannot be represented as a number.
Posted 24 April 2015 - 12:04 AM
It can, https://raw.githubusercontent.com/Selim042/Northbridge-Storage/master/version is what it points to, and I tested downloading it and turning it to a number in the Lua console.
Posted 24 April 2015 - 12:11 AM
If it works in the Lua console, then that suggests you're not setting rawRepoLocation to what you think you're setting it to. It's "https://raw.githubusercontent.com/Selim042/Northbridge-Storage/master/", right?
By the way, don't forget to close "response"!
Edit:
Ah, here we go:
By the way, don't forget to close "response"!
Edit:
Ah, here we go:
if response then
Edited on 23 April 2015 - 10:18 PM
Posted 24 April 2015 - 12:20 AM
Well that was a fail… thanks thoughIf it works in the Lua console, then that suggests you're not setting rawRepoLocation to what you think you're setting it to. It's "https://raw.githubusercontent.com/Selim042/Northbridge-Storage/master/", right?
By the way, don't forget to close "response"!
Edit:
Ah, here we go:if response then
Edited on 23 April 2015 - 10:22 PM