if http.request("http://lightos.webuda.com/lightos/version.inf") >= version then
version = false
end
I got the error 'startup:20: attempt to compare nil with number'. How can I fix this?
[Error][Fixed]startup:20: attempt to compare nil with number
#1
Posted 03 March 2013 - 06:23 AM
#2
Posted 03 March 2013 - 06:33 AM
http.request("http://www.google.com/")
local e = {os.pullEvent()}
if e[1] == "http_failure" then
print("Uh oh! Couldn't connect to google!")
return
end
local content = e[3].readAll()
e[3].close()
print(content)
I also noticed that you are trying to compare the result of an http request (a string) directly to a number. You need to convert the string into a number with tonumber(content).
#3
Posted 04 March 2013 - 03:48 AM
local version = http.get("http://lightos.webuda.com/lightos/version.inf")
write(version.readAll())
a = version.readAll()
version.close()
if tonumber(a) >= 011 then
uptodate = false
en
now I got 'startup:23: attempt to compare nil with number'
#4
Posted 04 March 2013 - 04:33 AM
#5
Posted 04 March 2013 - 05:25 AM
#6
Posted 04 March 2013 - 05:30 AM
#7
Posted 04 March 2013 - 05:33 AM
#8
Posted 04 March 2013 - 05:48 AM
#9
Posted 04 March 2013 - 06:01 AM
Bubba, on 04 March 2013 - 05:33 AM, said:
No, the problem is that doing readAll() causes it go be at the very last line (which is nil if read) and then he does another readAll() which returns nil.
It's like doing readLine() and then readLine() again - the second readLine() will read the second line and not the first.
#10
Posted 04 March 2013 - 06:27 AM
remiX, on 04 March 2013 - 06:01 AM, said:
Bubba, on 04 March 2013 - 05:33 AM, said:
No, the problem is that doing readAll() causes it go be at the very last line (which is nil if read) and then he does another readAll() which returns nil.
It's like doing readLine() and then readLine() again - the second readLine() will read the second line and not the first.
Ah yes. My mistake. Please ignore my response: foolish http noob here.
#11
Posted 04 March 2013 - 06:29 AM
Bubba, on 04 March 2013 - 06:27 AM, said:
remiX, on 04 March 2013 - 06:01 AM, said:
Bubba, on 04 March 2013 - 05:33 AM, said:
No, the problem is that doing readAll() causes it go be at the very last line (which is nil if read) and then he does another readAll() which returns nil.
It's like doing readLine() and then readLine() again - the second readLine() will read the second line and not the first.
Ah yes. My mistake. Please ignore my response: foolish http noob here.
Not only http
#12
Posted 04 March 2013 - 06:31 AM
remiX, on 04 March 2013 - 06:29 AM, said:
Nah I'm perfectly fine with the fs api. I just missed the fact that he used f.readAll() twice (didn't read through it very carefully).
Thank you for being so quick to confirm my idiocy though XD
#13
Posted 04 March 2013 - 09:54 AM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











