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

Can't figure out why this is returning nil

Started by Selim, 23 April 2015 - 09:54 PM
Selim #1
Posted 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.

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
Edited on 23 April 2015 - 10:00 PM
Bomb Bloke #2
Posted 23 April 2015 - 11:57 PM
Is it returning nil, or false?

What's "rawRepoLocation"?
Selim #3
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.
Bomb Bloke #4
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.
Selim #5
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.
Bomb Bloke #6
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:

if response then
Edited on 23 April 2015 - 10:18 PM
Selim #7
Posted 24 April 2015 - 12:20 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:

if response then
Well that was a fail… thanks though
Edited on 23 April 2015 - 10:22 PM