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

GitHub

Started by hbomb79, 21 July 2014 - 08:08 AM
hbomb79 #1
Posted 21 July 2014 - 10:08 AM
Hey there, having some problems with my program im running:


function getAvailableVersion(updateURL)
  for i = 1, 3 do
	response = http.get(updateURL)
if response then
	 data = response.readAll()
	 if currentVersion ~= data then
	print "Update Available, Downloading!"
	if not fs.exists("/systemFiles/Install/updater") then
	 print "Installer Missing!"
	  downloadFiles("https://raw.github.com/hbomb79/securitySystemPro/master/updater", "/systemFiles/Install/updater")
	end
	print ("Latest Version: "..data)
	print ("Running Version: "..currentVersion)
	print "Running Updater!"
	if fs.exists"/systemFiles/Install/updater" then
	shell.run "/systemFiles/Install/updater"
	else
	error "The Updater Is Missing! This Should Have Been Downloaded At Install, Reboot To Try Again, Or Report!"
	end
   else
	 print "You Are Running The Latest Version"
		error "Running Latest Version"
	 return true
  end
else
   error ("The URL: "..updateURL.." Does Not Seem To Exist [404]")
end
  end
  error ("[208] An error occurred whilst received a response from: "..updateURL)
end
getAvailableVersion("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/version")


even tho they both equal two it continues, the lines of code that print new and current both say two and yet it still says theres an update, where as if i go and change the line that says:

data = response.readAll()

to:

data = 2

Then it works fine!

Can someone tell me what im doing wrong?
Edited on 21 July 2014 - 08:09 AM
LBPHacker #2
Posted 21 July 2014 - 02:28 PM
.readAll returns a string. 2 is a number. For Lua, they are not equal. Try
local data = tonumber(response.readAll())
Edited on 21 July 2014 - 12:29 PM
hbomb79 #3
Posted 22 July 2014 - 01:10 AM
Thank you, I will try this when I get home
hilburn #4
Posted 22 July 2014 - 01:18 AM
An alternative would be

if CurrentVersion - data ~= 0 then
...

as Lua will allow you to do maths on a number-only string as if it was a number perfectly happily

Or you could store the current version as a string (more useful if you want to do "v1.13.4" etc)
hbomb79 #5
Posted 22 July 2014 - 01:36 AM
I think I will store the currentVerion as a string as right now it is CurrentVersion = 2 and I think I'll change it… That would be better, that means I can keep it as is correct?
LBPHacker #6
Posted 22 July 2014 - 09:06 PM
Yup, you can keep it as is, and if you want to introduce major and minor version numbers sometime in the future, you'd better store them in a single string anyway.
hbomb79 #7
Posted 23 July 2014 - 06:52 AM
Thanks guys, works like a charm :)/>