172 posts
Location
USA
Posted 31 August 2016 - 05:33 PM
Hi Guys!
I am currently working on an auto-updater for my new OS that im working on.
I am getting this error:
"autoupdater:48: attempt to index ? (a nil value)"
Code:
local url = "https://raw.githubusercontent.com/Carbon-OS/CarbonOS/System/latestversion"
local files = {
[1] = {
"/System/Images/boot",
"https://raw.githubusercontent.com/Carbon-OS/CarbonOS/master/System/Images/boot"
},
[2] = {
"startup",
"https://raw.githubusercontent.com/Carbon-OS/CarbonOS/master/startup"
},
[3] = {
"/Programs/LuaIDE/program",
"https://raw.githubusercontent.com/Carbon-OS/CarbonOS/master/Programs/LuaIDE/program"
},
[4] = {
"/Programs/Sketch/program",
"https://raw.githubusercontent.com/Carbon-OS/CarbonOS/master/Programs/Sketch/program"
},
[5] = {
"/Desktop/LuaIDE",
"https://raw.githubusercontent.com/Carbon-OS/CarbonOS/master/Desktop/LuaIDE"
},
[6] = {
"/Desktop/Sketch",
"https://raw.githubusercontent.com/Carbon-OS/CarbonOS/master/Desktop/Sketch"
},
[7] = {
"/System/Images/desktop",
"https://raw.githubusercontent.com/Carbon-OS/CarbonOS/master/System/Images/desktop"
},
[8] = {
"/System/settings",
"https://raw.githubusercontent.com/Carbon-OS/CarbonOS/master/System/settings"
},
[9] = {
"/System/autoupdater",
"https://raw.githubusercontent.com/Carbon-OS/CarbonOS/master/System/autoupdater"
},
[10] = {
"/System/.version",
"https://raw.githubusercontent.com/Carbon-OS/CarbonOS/master/System/.version"
},
[11] = {
"/os",
"https://raw.githubusercontent.com/Carbon-OS/CarbonOS/master/os"
}
}
req = http.get(v[2])
code = req.readAll()
shell.run("cd", "/System")
file = fs.open("latestversion", "w")
file.write(code)
file.close()
file = fs.open("latestversion", "r")
compare = fs.open(".version", "r")
local latestver = file.readLine()
local thisver = compare.readLine()
if latestver == thisver then
file.close()
compare.close()
fs.delete("latestversion")
shell.run("cd", "/")
fs.delete("/System")
fs.delete("/Programs")
fs.delete("/Desktop")
print("Updating...")
local req
local code
local file
for k,v in pairs(files) do end
print("Downloading ", v[2], "...")
req = http.get(v[2])
if req ~= nil then
code = req.readAll()
req.close()
else
print("Failed!")
end
file = fs.open(v[1], "w")
file.write(code)
file.close()
else
shell.run("/os")
end
Thank you!
3057 posts
Location
United States of America
Posted 31 August 2016 - 05:36 PM
req = http.get(v[2])
v doesn't exist, therefor you can't index it.
172 posts
Location
USA
Posted 31 August 2016 - 05:43 PM
for k,v in pairs(files) do end
i saw that doesn't that define v? Sorry im just not the best at CC
275 posts
Location
Turkey
Posted 31 August 2016 - 05:54 PM
for k,v in pairs(files) do end
i saw that doesn't that define v? Sorry im just not the best at CC
...es) do end
the
end at the end ends
for before you do anything in it.
Edited on 31 August 2016 - 03:55 PM
3057 posts
Location
United States of America
Posted 31 August 2016 - 06:14 PM
It does, but only within the loop. Line 48 is not within that loop.
172 posts
Location
USA
Posted 31 August 2016 - 06:24 PM
I removed the end and it says "bios:14: [string "autoupdater"]:83: 'end' expected (to close 'for' at line 70) and if i add an end it will have that same attempt to index nil error
If you want to see my full code for the OS so far then go to this link:
https://github.com/Carbon-OS/CarbonOSThe autoupdater file is in the System folder
I removed the end and it says "bios:14: [string "autoupdater"]:83: 'end' expected (to close 'for' at line 70) and if i add an end it will have that same attempt to index nil error
If you want to see my full code for the OS so far then go to this link:
https://github.com/Carbon-OS/CarbonOSThe autoupdater file is in the System folder
275 posts
Location
Turkey
Posted 31 August 2016 - 06:27 PM
172 posts
Location
USA
Posted 31 August 2016 - 06:34 PM
If i remove the if it will say that it needs an end statement at line 73
275 posts
Location
Turkey
Posted 31 August 2016 - 06:35 PM
If i remove the if it will say that it needs an end statement at line 73
Don't remove the if. Add a end where my highlighting ends.
3057 posts
Location
United States of America
Posted 31 August 2016 - 06:42 PM
Ugh.
first problem v isn't defined before this line runs.
second problemIf the versions don't match, you won't close the files and things will go wrong later. Close the files before the if statement.
this is your if statement. All of that. Fix the indentation
here the compiler expects you to end your for loop. Put an end before this line.
@Admicos - Stop giving bad advice. Your first post didn't address the problem at all, and commented on the wrong line. That line actually worked fine because, despite the terrible indentation, it was inside the for loop, not outside as you stated.
172 posts
Location
USA
Posted 31 August 2016 - 06:43 PM
I got "autoupdater:48: attempt to index ? (a nil value)"
Sorry if im annoying you.
Edit: Thank you for your advice KingofGamesYami. I am seeing if the problem is fixed (it takes a minute for the github raw download to update)
Edited on 31 August 2016 - 04:48 PM
3057 posts
Location
United States of America
Posted 31 August 2016 - 06:47 PM
Is line 48 still using v? If it is, you haven't fixed the first thing I said in the last post.
275 posts
Location
Turkey
Posted 31 August 2016 - 06:47 PM
@Admicos - Stop giving bad advice. Your first post didn't address the problem at all, and commented on the wrong line. That line actually worked fine because, despite the terrible indentation, it was inside the for loop, not outside as you stated.
I didn't say the if was outside. I said "
Add a end where my highlighting ends. " if i said where it starts, that would make the if outside the loop.
EDIT: The file is changed and my highlight is useless now.
Edited on 31 August 2016 - 04:48 PM
172 posts
Location
USA
Posted 31 August 2016 - 06:55 PM
I added an end to line 57 and i am getting "bios:14: [string "autoupdater"]:86: '<eof>' expected"
3057 posts
Location
United States of America
Posted 31 August 2016 - 06:58 PM
Why would you add an end to line 57? There's nothing to end there.
726 posts
Location
Rem is best girl
Posted 31 August 2016 - 07:00 PM
He didnt need add an end anywhere, just didnt indent it correctly.
172 posts
Location
USA
Posted 31 August 2016 - 07:08 PM
Then what line do i add the end to? You said i did not fix the end loop problem
3057 posts
Location
United States of America
Posted 31 August 2016 - 07:15 PM
172 posts
Location
USA
Posted 31 August 2016 - 07:30 PM
I dont know how to accept the pull request. Can you please tell me how to accept the pull request?
Edit: I just found out how to accept it
umm it says "autoupdater:58: attempt to index ? (a nil value)"
Edited on 31 August 2016 - 05:27 PM
3057 posts
Location
United States of America
Posted 31 August 2016 - 07:38 PM
Reboot the computer. The 'compare' file is probably still open somewhere.
172 posts
Location
USA
Posted 31 August 2016 - 07:44 PM
I rebooted the Computer, problem still is there. I even tried placing another PC and running the OS and i still got the error.
You can see by typing in pastebin run 5BsVEnu3 (My OS installer)