Jump to content




GitHub


  • You cannot reply to this topic
6 replies to this topic

#1 hbomb79

  • Members
  • 352 posts
  • LocationOrewa, New Zealand

Posted 21 July 2014 - 09: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 by Hbomb_79, 21 July 2014 - 09:09 AM.


#2 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 21 July 2014 - 01:28 PM

.readAll returns a string. 2 is a number. For Lua, they are not equal. Try
local data = tonumber(response.readAll())

Edited by LBPHacker, 21 July 2014 - 01:29 PM.


#3 hbomb79

  • Members
  • 352 posts
  • LocationOrewa, New Zealand

Posted 22 July 2014 - 12:10 AM

Thank you, I will try this when I get home

#4 hilburn

  • Members
  • 153 posts
  • LocationLondon, England

Posted 22 July 2014 - 12: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)

#5 hbomb79

  • Members
  • 352 posts
  • LocationOrewa, New Zealand

Posted 22 July 2014 - 12: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?

#6 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 22 July 2014 - 08: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.

#7 hbomb79

  • Members
  • 352 posts
  • LocationOrewa, New Zealand

Posted 23 July 2014 - 05:52 AM

Thanks guys, works like a charm :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users